-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdouble or quits new.py
53 lines (37 loc) · 1.14 KB
/
double or quits new.py
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
49
50
51
52
#open a file
fi = open("score.txt", "r")
#get the data
data = fi.readline()
#close the file
fi.close()
highscore = int(data.split(":")[0])
highname = data.split(":")[1]
print("current highscore is" + str(highscore) + "held by" + highname)
#Import the module for creating random numbers
import random
#Check if the user wants to keep playing or quit
play = 'y'
#Start the user at one
score = 1
#Check if they want to keep playing
while play.lower() == 'y':
#generate an integer between 0,3
fate = random.randint(0,3)
if fate == 0:
#they lose and score is set to 0
print("You lose!!!")
score = 0
#They lost so they can choose not to play again
play = 'n'
else:
# display their new score (score*2)
score *= 2
# print their new score
print("Your score is now:" + str(score))
# Ask if they want to try and double their score
play = input("Do you want to try to double your score? [y/n]")
if score > highscore:
newname = input("HIGH SCORE! Enter your name: ")
fi = open("score.txt", "w")
fi.write(str(score) + ":" + newname)
fi.close()