Skip to content

Commit 89cc292

Browse files
committed
Python Course
1 parent 4e7221d commit 89cc292

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

File.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,27 @@
5252
with open('mydata.txt','a') as f:
5353
a=f.write("now close function tension finish")
5454
print(a)
55-
55+
56+
#now use "in" with ".open()" function to check word in present in string or not?
57+
58+
with open('mydata.txt','r') as f:
59+
a=f.read()
60+
if "now" in a:
61+
print(True) #we got true because in file "mydata.txt" we have "now" word.
62+
else:
63+
print(False)
64+
65+
#update "gameData.txt" if number you got higher from stored number
66+
67+
def score():
68+
return 501
69+
get=score()
70+
#first fwe have to read this file
71+
with open('gameData.txt') as f:
72+
Read=int(f.read()) # we have to take as "integer" thats why i use "int"
73+
if Read<get:
74+
#now we have to write or append in "gameData.txt" if you score is higher only than it can be change
75+
with open('gameData.txt','w') as f:
76+
f.write(str(get)) # why str? because ".txt" can only store sting so we have to change result into string
77+
#now 501 will replace in file with 500
78+
# but this will happen if newer value is greater than past value.

gameData.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
501

0 commit comments

Comments
 (0)