-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoins.py
More file actions
48 lines (34 loc) · 1.13 KB
/
coins.py
File metadata and controls
48 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from tkinter import messagebox
def coin_increase(coins_earned):
f1 = open ("coins.txt", "r+")
coins_read=(f1.read())
if coins_read == '':
f1.write(str(coins_earned))
messagebox.showinfo("Coins:","Coins:"+str(coins_earned))
return coins_earned
else:
coins_read = int(coins_read)
f1.seek(0)
f1.truncate()
new_coins = coins_read+coins_earned
f1.write(str(new_coins))
messagebox.showinfo("Coins:","Coins:"+str(new_coins))
f1.close()
return new_coins
def coin_decrease(coins_spent):
f1 = open ("coins.txt", "r+")
coins_read = f1.read()
if coins_read!='':
coins_read=int(coins_read)
else:
coins_read = 0
f1.seek(0)
f1.truncate()
if coins_read>=100:
new_coins = coins_read-coins_spent
f1.write(str(new_coins))
f1.close()
return True
else:
messagebox.showinfo("Insufficient coins","You do not have enough coins! :( \nComplete some tasks to play again!")
return False