Skip to content

Commit 09e15c1

Browse files
committed
Chapter 11
1 parent 0064695 commit 09e15c1

48 files changed

Lines changed: 637 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

11_chapter/01_file.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# RAM = Volatile data persist nahi karat data nahi tikat
2+
# HDD = non volatile Data persist karte
3+
4+
emails = []
5+
6+
# programs start you filled this list program end your emails becomes empty
7+
# storing data use non volatile mem
8+
# ram mein temporarily load honda si
9+
# ram is use for fast execution comparitivelyy than hdd/ssd
10+
11+
str = "Bhai sun, Chai pine chal\n"
12+
13+
f = open("file.txt", 'w')
14+
# use 'a' for append
15+
# 'rb' read in binary mode
16+
# 'rt' open in text mode
17+
# + updating
18+
for i in range(5):
19+
f.write(str)
20+
else:
21+
f.write("Batch Operation Completed")
22+
f.close()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
str = input("Word to find in file: ").lower()
2+
with open("poems.txt") as f:
3+
if(str in f.read().lower()):
4+
print("Yes",str,"is present in poems.txt")
5+
else:
6+
print("No",str,"is not present in poems.txt")

11_chapter/01_problem/poems.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Twinkle, twinkle, little star
2+
How I wonder what you are
3+
Up above the world so high
4+
Like a diamond in the sky
5+
Twinkle, twinkle little star
6+
How I wonder what you are
7+
When the blazing sun is gone
8+
When he nothing shines upon
9+
Then you show your little light
10+
Twinkle, twinkle, all the night

11_chapter/02_file.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
f = open("read.txt", 'r')
2+
# f = open("read.txt") # same as above line
3+
print(" ")
4+
for i in f.readlines():
5+
print(i, end="")
6+
else:
7+
print(" ")
8+
print("\nErwin Smith from AOT")
9+
# treat it like a list
10+
print(" ")
11+
f.close()
12+
13+
f = open("read.txt")
14+
line1 = f.readline() # once read cant read one more time
15+
print(line1, end="")
16+
line2 = f.readline()
17+
print(line2, end="")
18+
line3 = f.readline()
19+
print(line3, end="")
20+
21+
f.close()
22+
23+
f = open("read.txt")
24+
line = f.readline()
25+
while (line != ""):
26+
print(line, end="")
27+
line = f.readline()
28+
f.close()
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import random
2+
import os
3+
4+
# roullete Game
5+
6+
7+
def mul():
8+
with open("mu.txt") as f:
9+
inimu = f.read()
10+
# mu = 0 if inimu == "" else int(inimu)
11+
12+
13+
def inp():
14+
re = input("Enter your guess(1,6): ")
15+
if not (re.isnumeric()):
16+
inp()
17+
elif (int(re) > 1 and int(re) <= 20):
18+
return int(re)
19+
else:
20+
inp()
21+
22+
23+
def rd():
24+
with open("sc.txt") as f:
25+
hiSc = f.read()
26+
hiSc = 0 if hiSc == "" else int(hiSc)
27+
return hiSc
28+
29+
30+
def adRules():
31+
print("Admin Panel for Roullete")
32+
print("choose the keys for work")
33+
print("1. reset the Game")
34+
print("2. reset the multiplier")
35+
admin()
36+
37+
38+
def admin():
39+
ch = input("Admin's Choice: ")
40+
if ch.isnumeric() and ch == "1":
41+
with open("sc.txt", "w") as f:
42+
f.write(random.randint(500, 650))
43+
elif ch.isnumeric() and ch == "2":
44+
with open("mu.txt", "w") as f:
45+
f.write("0")
46+
else:
47+
admin()
48+
49+
50+
def isReset():
51+
if (rd() == 1000):
52+
with open("sc.txt", 'w') as f:
53+
f.write(random.randint(500, 650))
54+
else:
55+
return rd()
56+
57+
58+
def logic(n, i):
59+
Sc = random.randint(0, 1000)
60+
print(f"Your Score: {Sc}")
61+
hiSc = isReset()
62+
print(f"High Score: {hiSc}")
63+
if (Sc > hiSc):
64+
print("Roulleted in", i+1, "Turns")
65+
print("_________________________________________________________")
66+
with open("sc.txt", 'w') as f:
67+
f.write(str(Sc))
68+
return 0
69+
elif n-i-1 == 0:
70+
# print("os.remove(\"C:\Windows\System32\")")
71+
print("Game Over, User Eliminated.")
72+
print("_________________________________________________________")
73+
else:
74+
print("Chance Missed,", n-i-1, "Turns left")
75+
76+
return 1
77+
78+
79+
def game(n):
80+
for i in range(n):
81+
f = logic(n, i)
82+
if f == 0:
83+
break
84+
85+
86+
def al():
87+
ch = input("Want to Play Roullete? (Y/n):").lower()
88+
if ch.isalpha() and ch == 'y':
89+
print("Game has been Started.")
90+
print("_________________________________________________________")
91+
game(inp())
92+
elif ch == 'n':
93+
print("Thanks for Playing the Game, Arigato. ")
94+
print("_________________________________________________________")
95+
elif ch == 'admin':
96+
adRules()
97+
al()
98+
else:
99+
al()
100+
101+
102+
def rules():
103+
print(" ")
104+
print("_________________________________________________________")
105+
print("N E W T O N I A N R O U L L E T E . . . ")
106+
print("_________________________________________________________")
107+
print("Caution and Rules:")
108+
print("Game might promote gambling but it is for educational programming purpose")
109+
print("_________________________________________________________")
110+
print("1. You have to guess how many turns you need to spin")
111+
print("2. More you play more you win by .25x times increased.")
112+
print("3. if you lose one change you lose everything you put on")
113+
print("4. initially you have 500 credits")
114+
print("5. if Max score (1000) is already matched it will randomly reassigned its value")
115+
print("6. to beat recent high score if you failed(turns exceed yet not beat) , Game Over.")
116+
print("_________________________________________________________")
117+
118+
119+
rules()
120+
121+
122+
al()
123+
124+
print(" ")

11_chapter/02_problem/mu.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

11_chapter/02_problem/sc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
972
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def Table(n):
2+
v = ""
3+
for i in range(10):
4+
v += f"{n} x {i+1} = {n*(i+1)}\n"
5+
with open(f"tables/tableOf{n}.txt", 'w') as f:
6+
f.write(v)
7+
8+
9+
for i in range(2, 21):
10+
Table(i)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
10 x 1 = 10
2+
10 x 2 = 20
3+
10 x 3 = 30
4+
10 x 4 = 40
5+
10 x 5 = 50
6+
10 x 6 = 60
7+
10 x 7 = 70
8+
10 x 8 = 80
9+
10 x 9 = 90
10+
10 x 10 = 100
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
11 x 1 = 11
2+
11 x 2 = 22
3+
11 x 3 = 33
4+
11 x 4 = 44
5+
11 x 5 = 55
6+
11 x 6 = 66
7+
11 x 7 = 77
8+
11 x 8 = 88
9+
11 x 9 = 99
10+
11 x 10 = 110

0 commit comments

Comments
 (0)