forked from LewisAndClark-CSD/Chapter_3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMod_Guess_My_Number.py
More file actions
36 lines (28 loc) · 830 Bytes
/
Mod_Guess_My_Number.py
File metadata and controls
36 lines (28 loc) · 830 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
#! /usr/bin/python3
# Program Name: Mod_Guess_My_Number.py
# Author: Luke Gosnell
# Date Writen: 10/8/2014
import random
#Opening Remarks
print("Welcome to 'Guess My Number'!")
print("I'm thinking of a number between 1 and 100.")
print("Try to guess it in as few attempts as possible.")
# set the initial values
the_number = random.randint(1, 100)
guess = int(input("Guess: "))
tries = 1
# guessing loop
while guess != the_number:
if tries >= 5:
print("Too many tries! GAME OVER!")
exit()
elif guess > the_number:
print("Lower!")
else:
print("Higher!")
tries += 1
guess = int(input("Guess a number: "))
print("You guessed it! The number was", the_number)
print("And it only took you", tries, "tries!\n")
#Program Closing
input("Press the enter key to exit.")