-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5_12.py
More file actions
29 lines (17 loc) · 629 Bytes
/
5_12.py
File metadata and controls
29 lines (17 loc) · 629 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
"""
12. Write a program that asks the user to guess a random number between 1 and 10. If they guess
right, they get 10 points added to their score, and they lose 1 point for an incorrect guess. Give
the user five numbers to guess and print their score after all the guessing is done.
"""
import random
score = 0
for i in range(5):
number = random.randint(1,10)
user_guess = eval(input('Guess a number(1-10):'))
if(number == user_guess):
print('computer:',number,'guess:',user_guess,'correct')
score += 10
else:
print('computer:',number,'guess:',user_guess,'wrong')
score -= 1
print('Your score:',score)