-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnumberguess.py
More file actions
27 lines (23 loc) · 833 Bytes
/
Copy pathnumberguess.py
File metadata and controls
27 lines (23 loc) · 833 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
'''The task is to create a script that generates a random number between a fixed range, and if the user guesses the number right in three chances, then user wins otherwise user lose.'''
# Path: Number Guess/numberguess.py
import random
def number_guess():
# initialize score
score = 0
# generate a random number
number = random.randint(1, 10)
# take input from the user
guess = int(input("Guess the number between 1 and 10: "))
# check if the user guessed the number
for i in range (1,4,1):
if guess == number:
score = score + 1
print ("You guessed the number right!")
else:
print("You guessed the number wrong!")
exit()
if score == 3:
print("You win!")
# main function
if __name__ == "__main__":
number_guess()