Skip to content

Commit dfdbb14

Browse files
Add files via upload
1 parent ecd7f02 commit dfdbb14

34 files changed

+4997
-618
lines changed

Grocery List Creator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
'''
22
Grocery List Creator Python program
33
4-
Created by Joseph C. Richardson
4+
Created by Joseph C. Richardson, GitHub.com
55
66
This is a full functional grocery list Python program example to add to my Python book.
77
Feel free to copy this Python program example if you like. See what you can do with it.
88
Please enjoy.
99
'''
10+
# HIGHLIGHT AND COPY CODE, THEN PASTE INTO YOUR PREFERABLE PYTHON APP/IDLE
11+
1012
import os
1113

1214
text_colours=(
@@ -41,7 +43,7 @@
4143

4244
f'{double_line_break}{indent}Please type your grocery list item price: $', # index 3
4345

44-
f'{double_line_break}{indent}{text_colours[5]}You have', # indext 4
46+
f'{double_line_break}{indent}{text_colours[5]}You have', # index 4
4547

4648
'items in your grocery list.', # index 5
4749

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Input Fibonacci Number Sequence Python program example.
2+
3+
# Created by Joseph C. Richardson, GitHub.com
4+
5+
# HIGHLIGHT AND COPY CODE, THEN PASTE INTO YOUR PREFERABLE PYTHON APP/IDLE
6+
7+
# Input Fibonacci Number Sequence example, using a set{}
8+
9+
num1,num2=0,1
10+
11+
fib={num1,num2}
12+
13+
words=(
14+
'is in the Fibonacci Sequence.',
15+
'is not in the Fibonacci Sequence.',
16+
'Please enter a correct Fibonacci Sequence Number: ',
17+
'Sorry! Numbers only.',
18+
'Memory Error!'
19+
)
20+
21+
try:
22+
x=int(input(words[2]).strip())
23+
24+
for i in range(x):
25+
fib_num=num1+num2
26+
fib.add(fib_num)
27+
num1=num2
28+
num2=fib_num
29+
30+
if x in fib:
31+
print(x,words[0])
32+
33+
elif x not in fib:
34+
print(x,words[1])
35+
36+
except ValueError:
37+
print(words[3])
38+
39+
except MemoryError:
40+
print(words[4])

Know Your Polygons.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Know Your Polygons
2+
3+
# Created by Joseph C. Richardson, GitHub.com
4+
5+
# HIGHLIGHT AND COPY CODE, THEN PASTE INTO YOUR PREFERABLE PYTHON APP/IDLE
6+
7+
# See what happens when you type and execute/run this guessing
8+
# game program example below. Note: you must execute/run the
9+
# program from the OS output screen, via double-clicking the Python
10+
# program file itself.
11+
12+
# Save the Python file as 'Know Your Polygons'
13+
14+
import os
15+
16+
tc=(
17+
'\x1b[31m',
18+
'\x1b[32m',
19+
'\x1b[33m',
20+
'\x1b[34m',
21+
'\x1b[35m',
22+
'\x1b[36m',
23+
'\x1b[37m',
24+
'cls'
25+
)
26+
27+
question_prompts1=(
28+
f'{tc[2]}How many sides does a Triangle have?\n\n{tc[1]}(a) {tc[2]}four sides\n\
29+
{tc[1]}(b) {tc[2]}three sides\n{tc[1]}(c) {tc[2]}two sides',
30+
31+
f'{tc[2]}How many sides does a Square have?\n\n{tc[1]}(a) {tc[2]}Two sides\n\
32+
{tc[1]}(b) {tc[2]}Three sides\n{tc[1]}(c) {tc[2]}Four sides',
33+
34+
f'{tc[2]}How many sides does a Pentagon have?\n\n{tc[1]}(a) {tc[2]}four sides\n\
35+
{tc[1]}(b) {tc[2]}five sides\n{tc[1]}(c) {tc[2]}Three sides',
36+
37+
f'{tc[2]}How many sides does a Hexagon have?\n\n{tc[1]}(a) {tc[2]}six sides\n\
38+
{tc[1]}(b) {tc[2]}five sides\n{tc[1]}(c) {tc[2]}two sides',
39+
40+
f'{tc[2]}How many sides does a Octagon have?\n\n{tc[1]}(a) {tc[2]}four sides\n\
41+
{tc[1]}(b) {tc[2]}six sides\n{tc[1]}(c) {tc[2]}eight sides',
42+
43+
f'{tc[2]}How many sides does a Dodecagon have?\n\n{tc[1]}(a) {tc[2]}eight \
44+
sides\n{tc[1]}(b) {tc[2]}three sides\n{tc[1]}(c) {tc[2]}twelve sides',
45+
46+
f'{tc[2]}How many sides does a Hexadecagon have?\n\n{tc[1]}(a) {tc[2]}sixteen \
47+
sides\n{tc[1]}(b) {tc[2]}eight sides\n{tc[1]}(c) {tc[2]}six sides'
48+
)
49+
50+
prompt=('b','c','b','a','c','c','a')
51+
52+
score=0
53+
loop=0
54+
55+
while loop<=6:
56+
57+
os.system(tc[7])
58+
button=input((tc[1])+'\nKnow Your Polygons!\n\n'+(tc[2])+'Know Your Polygons\n\n'+\
59+
question_prompts1[loop]+'\n\n'+(tc[0])+'READY:'+(tc[1])).strip()
60+
61+
if button==(prompt[loop]):
62+
score+=1
63+
64+
loop+=1
65+
66+
os.system(tc[7])
67+
print(f'\n{tc[2]}Know Your Polygons\n\n{tc[2]}You got \
68+
{score}/{len(question_prompts1)} questions correct.\nCongratulations! Your total \
69+
Prize Winnings: {tc[1]}${score*100*score:,}.00 {tc[2]}Dollars.\n\n{tc[0]}READY:')
70+
71+
input('\nEND OF PROGRAM! Press Enter to quit.')

Knowledge Poem File EXE.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
from FileMenuExample import file_menu
3+
4+
os.system('title J.C.R Soft~Choice')
5+
6+
sounds=(
7+
'Ring08','Alarm05','Windows Proximity Notification'
8+
)
9+
10+
text_features=(
11+
'cls', # index 0 = clear screen
12+
'*'*118, # index 1 = 118 asterisks
13+
'\x1b[31m', # index 2 = red
14+
'\x1b[32m', # index 3 = green
15+
'\x1b[33m', # index 4 = yellow
16+
'\x1b[34m', # index 5 = blue
17+
'\x1b[35m', # index 6 = purple
18+
'\x1b[36m', # index 7 = cyan
19+
'\x1b[37m' # index 8 = white
20+
)
21+
22+
knowledge_poem=(
23+
f'''\n{text_features[7]}‘Knowledge’
24+
is a free invention of the heart and of the mind itself!
25+
The only textbooks needed, are the heart and the mind.
26+
The only exam to be written is the key to ponder into wonder.
27+
For the heart and the mind hold the key to the greatest diploma of all,
28+
the dream’s creation of our imagination.
29+
For the heart and the mind are thus, the greatest teachers of us…
30+
Believe in yourself! For you are their greatest student.
31+
32+
THIS BELONGS TO EVERY MAN, WOMAN AND CHILD
33+
Never give up your dream, no matter how far away it may seem to be, because that is when it is ever so
34+
close to becoming true. If you dream of something long enough and strong enough, your dream will come
35+
true, when you least expect it. Always remember, we are never too young or too old to dream and use our
36+
imagination, for we only get one and it is ours forever. May your heart be filled with courage and
37+
compassion, and your mind be as limitless and as wondrous as the universe itself!
38+
If you dream it, you can be it. Believe it!\n'''
39+
)
40+
41+
logo=(
42+
f'\njoshua.computers.read/information', # index 0 = logo
43+
f'\n\nall rights reserved.' # index 1 = logo
44+
)
45+
46+
text_info=(f'\nPress (ENTER) to begin:')
47+
48+
class Knowledge:
49+
def ponder():
50+
os.system(text_features[0])
51+
print(knowledge_poem)
52+
def jcr():
53+
print(f'{text_features[2]}{text_features[1]}{text_features[8]}{logo[0].upper()}{logo[1].title()}')
54+
input(text_info).lower().strip()
55+
file_menu()
56+
57+
Knowledge.ponder()
58+
Knowledge.jcr()

Knowledge Poem Python program.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Knowledge Poem Python program example.
2+
3+
# Created by Joseph C. Richardson, GitHub.com
4+
5+
# HIGHLIGHT AND COPY CODE, THEN PASTE INTO YOUR PREFERABLE PYTHON APP/IDLE
6+
7+
# Note: after you save your file, you must double click this file to view it's cool coloured
8+
# text and layout.
9+
10+
import time,os;os.system('title,Knowledge Poem')
11+
12+
text_colours=(
13+
'\x1b[31m', # index 0 = red
14+
'\x1b[32m', # index 1 = green
15+
'\x1b[33m', # index 2 = yellow
16+
'\x1b[34m', # index 3 = blue
17+
'\x1b[35m', # index 4 = purple
18+
'\x1b[36m', # index 5 = cyan
19+
'\x1b[37m' # index 6 = white
20+
)
21+
22+
knowledge_poem=(
23+
f'''\n{text_colours[5]}'Knowledge'
24+
is a free invention of the heart and of the mind itself!
25+
The only textbooks needed, are the heart and the mind.
26+
The only exam to be written is the key to ponder into wonder.
27+
For the heart and the mind hold the key to the greatest diploma of all,
28+
the dream's creation of our imagination.
29+
For the heart and the mind are thus, the greatest teachers of us…
30+
Believe in yourself! For you are their greatest student.
31+
32+
THIS BELONGS TO EVERY MAN, WOMAN AND CHILD
33+
Never give up your dream, no matter how far away it may seem to be, because that is when it is
34+
ever so close to becoming true. If you dream of something long enough and strong enough, your
35+
dream will come true, when you least expect it. Always remember, we are never too young or too
36+
old to dream and use our imagination, for we only get one and it is ours forever. May your heart
37+
be filled with courage and compassion, and your mind be as limitless and as wondrous as the
38+
universe itself! If you dream it, you can be it. Believe it!\n'''
39+
)
40+
41+
while True:
42+
os.system('cls')
43+
letter=input(f'{knowledge_poem}\n{text_colours[1]}Type a word or letter from this poem, and I will tell you how \
44+
many times it\'s been used in it.\nNote: words and letters are case sensitive.\n\nType (quit) to close the program: ').strip()
45+
46+
if letter=='quit':
47+
break
48+
49+
elif len(letter)<=1:
50+
print(f'\n{text_colours[2]}The letter " {letter} " has been used {knowledge_poem.count(letter)} times in this poem.')
51+
time.sleep(2)
52+
53+
elif len(letter)>=2:
54+
print(f'\n{text_colours[2]}The word " {letter} " has been used {knowledge_poem.count(letter)} times in this poem.')
55+
time.sleep(2)

Lambda Function Exp.py

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,64 @@
1-
# LAMBDA functions are 'nameless', 'anonomous' functions. They are still very new to me, but at least I can cheat. lol
1+
# LAMBDA functions are 'nameless', 'anonymous' functions.
2+
# They are still very new to me, but at least we can cheat. lol
3+
4+
# HIGHLIGHT AND COPY CODE, THEN PASTE INTO YOUR PREFERABLE PYTHON APP/IDLE
25

36
def num(x):
47
return x**3
58
print(num(10))
69

710
num=lambda x:x**3
811
print(num(10))
9-
1012
'''----------------------------------------------------------------'''
11-
1213
def num(x):
1314
return lambda x:x**3
1415
c=num(3)
1516
print(c(10))
16-
1717
'''----------------------------------------------------------------'''
18-
1918
mylist=[1,2,3,4,5,6]
2019
newlist=list(filter(lambda a:(a/3==2),mylist))
2120
print(newlist)
22-
2321
'''----------------------------------------------------------------'''
24-
2522
mylist=[1,2,3,4,5,6]
2623
p=list(map(lambda a:(a/3!=2),mylist))
2724
print(p)
28-
2925
'''----------------------------------------------------------------'''
30-
3126
from functools import reduce
3227
r=reduce(lambda a,b:a+b,[23,56,43,98,1])
3328
print(r)
34-
3529
'''----------------------------------------------------------------'''
36-
3730
s=lambda a: a*a
3831
print(s(4))
39-
4032
'''----------------------------------------------------------------'''
41-
4233
d=lambda x,y:3*x+4*y
4334
print(d(4,7))
44-
4535
'''----------------------------------------------------------------'''
46-
4736
x=lambda a,b:(a+b)**2
4837
print(x(3,4))
49-
5038
'''----------------------------------------------------------------'''
51-
5239
x=lambda a:a+10
5340
print(x(5))
54-
5541
'''----------------------------------------------------------------'''
56-
5742
x=lambda a,b:a*b
5843
print(x(5,6))
59-
6044
'''----------------------------------------------------------------'''
61-
6245
x=lambda a,b,c:a+b+c
6346
print(x(5,6,2))
64-
6547
'''----------------------------------------------------------------'''
66-
6748
def myfunc(n):
6849
return lambda a:a*n
6950

7051
mydoubler=myfunc(2)
7152

7253
print(mydoubler(11))
73-
7454
'''----------------------------------------------------------------'''
75-
7655
def myfunc(n):
7756
return lambda a:a*n
7857

7958
mytripler=myfunc(3)
8059

8160
print(mytripler(11))
82-
8361
'''----------------------------------------------------------------'''
84-
8562
def myfunc(n):
8663
return lambda a:a*n
8764

Laser Wars.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Try this fun tkinter Python program example, I call LASER WARS
2+
3+
# Created by Joseph C. Richardson, GitHub.com
4+
5+
import time
6+
from random import*
7+
from tkinter import*
8+
my_window=Tk()
9+
10+
my_window.title('LASER WARS')
11+
12+
def random_colour_code():
13+
hex_chars=['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
14+
colour_code='#'
15+
16+
for i in range(0,6):
17+
colour_code=colour_code+choice(hex_chars)
18+
return colour_code
19+
20+
my_canvas=Canvas(my_window,width=1920,height=1080,background='#000000')
21+
my_canvas.grid(row=0,column=0)
22+
23+
while True:
24+
x1=randint(-500,1920)
25+
y1=randint(-500,1920)
26+
x2=randint(-500,1920)
27+
y2=randint(-500,1920)
28+
29+
x3=randint(-500,1920)
30+
y3=randint(-500,1920)
31+
x4=randint(-500,1920)
32+
y4=randint(-500,1920)
33+
34+
x5=randint(-500,1920)
35+
y5=randint(-500,1920)
36+
x6=randint(-500,1920)
37+
y6=randint(-500,1920)
38+
39+
random_width=randint(0,10)
40+
my_canvas.create_line(x1,y1,x2,y2,fill=random_colour_code(),width=random_width)
41+
my_canvas.create_line(x3,y3,x4,y4,fill=random_colour_code(),width=random_width)
42+
my_canvas.create_line(x5,y5,x6,y6,fill=random_colour_code(),width=random_width)
43+
44+
my_canvas.update()
45+
time.sleep(.08)
46+
my_canvas.delete('all')
47+
48+
my_window.mainloop()

0 commit comments

Comments
 (0)