File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 52
52
with open ('mydata.txt' ,'a' ) as f :
53
53
a = f .write ("now close function tension finish" )
54
54
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.
Original file line number Diff line number Diff line change
1
+ 501
You can’t perform that action at this time.
0 commit comments