-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuess_number.py
More file actions
27 lines (25 loc) · 1.03 KB
/
Guess_number.py
File metadata and controls
27 lines (25 loc) · 1.03 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
#Used random module to select a number from your input and this will match to yours input
import random
list_int = []
char_sep='-'
for i in range(0,6):
list_int.append(i)
print ("{:<30} {} ".format(" ",(char_sep*100)))
print ("\n\n{:<30} Enter charecters for input to stop execution\n\n".format(" "))
print ("{:<30} Enter numbers in range of 1 to 5 \n\n".format(" "))
print ("{:<30} {} \n\n".format(" ",(char_sep*100)))
while True:
# user_input = input("Would you like to play? (Y/n):")
user_number = random.choice(list_int)
# if user_input == "n":
# break
try:
user_input_guess=int(input("Enter the number you guess: "))
except:
print ("{:<30}Enter only numbers as input charecters".format(""))
print ("{:<30}Stopping execution".format(""))
exit(1)
if user_number == user_input_guess:
print ("{:<30}Congratulations guessed number correctly!!!!".format(" "))
else:
print ("{:<30}Sorry!!, you need to guess {}".format(" ",user_number))