forked from 0xfaust/NSA_COMP3321
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_19.py
30 lines (24 loc) · 970 Bytes
/
03_19.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
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
'''Lecture 03, Exercise 19
Challenge: Write a 'Guess my number' game that generates a random number and
gives your user a fixed number of guesses. Use input to get the user's guesses.
Think about what loop type you might use and how you might provide feedback
based on the user's guesses. Hint: what type does input return? You might need
to convert it to a more useful type... However, now what happens if your user
inputs something that isn't a number?
'''
import random
def guess_my_number():
answer = random.randint(0, 10)
turns = 5
print('Guess a number between 1 and 10')
for turn in range(0, turns):
print('You have ' + str(turns - turn) + ' guess(\'s) left')
guess = input('Please make guess number ' + str(turn+1) + ': ')
if int(guess) == answer:
print('Correct!')
exit()
else:
print('Incorrect!')
guess_my_number()