-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExercise_usingRandomInFunctions.py
More file actions
50 lines (21 loc) · 998 Bytes
/
Copy pathExercise_usingRandomInFunctions.py
File metadata and controls
50 lines (21 loc) · 998 Bytes
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
import random
def func_GetRandom(): #function to generate random number
randVar = random.randint(0,1000)
return randVar
x = func_GetRandom() #generates an initial value for the random number when code is first run
def startGame(randomNumber):
print('The game has started. The random value is:',randomNumber)
level1(randomNumber)
def level1(randomNumber):
print('The game has progressed to level 1. The random value is',randomNumber)
level2(randomNumber)
def level2(randomNumber):
print('The game has progressed to level 2. The random value is',randomNumber)
restartGame = input('Restart game? Y/N')
if restartGame.upper() == 'Y':
gameRestart()
def gameRestart(): #generates a new random number when the game restarts
x = func_GetRandom()
print('The game has restarted. The random value is',x)
startGame(x)
startGame(x)