-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05-GuessingGame.py
More file actions
34 lines (22 loc) · 1 KB
/
05-GuessingGame.py
File metadata and controls
34 lines (22 loc) · 1 KB
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
# Author: Ian Burke
# Module: Emerging Technologies
# Date: September, 2017
# Problem Sheet: https://emerging-technologies.github.io/problems/python-fundamentals.html
import random # import random package to use random function
# random function generates a random number between 1 and 100 and store in num.
num = random.randint(0, 101)
print ("Guess a number between 1 and 100")
guessCount = 0 # counter to count the number of guesses
# create a while loop for user to guess multiple times
while True:
guess = input() # user's guess is stored as int in guess
guess = int(guess)
guessCount += 1 # increment count by + 1 for every guess
if guess < num: #if user's guess is less than random num then..
print("Too low")
elif guess > num: #if guess is bigger than number then..
print("Too high")
elif guess == num: #user guess equals number then..
print("Winner winner chicken dinner!")
print("Guesses taken: " , guessCount)
break # end the while loop