Program Description:
This program allows you to play a little game where it ask you to guess for a specific number between 1 and 100. The program would let you know if your guess is way too off or you are close to the random number that was generated. it would also tell you if your number has to be higher or lower. There is two version which both are similar programs: the first allows you to have infinite attempts and the second one allow you five attempts.
Version One:
import random
import sys
print (“Hello There!”)
answer = input(“Would you like to play a little game? “)
if answer == “Yes” or answer == “yes”:
print (“Nice”)
elif answer == “No” or answer == “no”:
print (“Okay. Have a nice day!!!”)
sys.exit()
rules = (“The rules of this game are simple. 1) I would generated a random number between 1 and 100, 2) You must guess, and 3) You have infinite attempts.”)
present = input(“Would you like to know the rules? “)
if str(present) == “Yes” or str(present) == “yes” or str(present) == “Sure” or str(present) ==”sure”:
print (rules)
elif str(present) == “No” or present == “no”:
print (“Okay. Lets continue then.”)
x = random.randint(1, 100)
print (“A random number has been chosen”)
g = input(“What is the number you are guessing? “)
while int(g) > x or int(g) < x:
if int(g) > x + 10:
print (“Too high, please try again.”)
g = input(“What is your next guess? “)
elif int(g) < x – 10:
print (“Too low, please try again.”)
g = input(“What is your next guess? “)
if int (g) > x and int(g) <= x + 9:
print (“You are close. Go lower”)
g = input(“What is your next guess?”)
elif int(g) < x and int(g) >= x – 9:
print (“You are close. Go higher.”)
g = input(“What is your next guess?”)
if int(g) == x :
print (“Congratulations, you found the correct number. (✧ω✧)”)
print (“Thanks for playing!!! \(^▽^)/”)
sys.exit()
Version Two:
import random
import sys
print (“Hello There!”)
answer = input(“Would you like to play a little game? “)
if str(answer) == “Yes” or answer == “yes” or answer == “y” or answer == “Y”:
print (“Nice”)
elif str(answer) == “No” or answer == “no”:
print (“Okay. Have a nice day!!!”)
sys.exit()
rules = (“The rules of this game are simple. 1) I would generated a random number between 1 and 100, 2) You must guess, and 3) You have 5 attempts.”)
present = input(“Would you like to know the rules? “)
if str(present) == “Yes” or str(present) == “yes” or str(present) == “Y” or str(present) ==”y”:
print (rules)
elif str(present) == “No” or str(present) == “no” or present == “n” or present == “N”:
print (“Okay. Lets continue then.”)
x = random.randint(1, 100)
print (“A random number has been chosen”)
a = 5
if a == 5:
print (“You have five attempts.”)
while a > 0:
g = input(“What is the number you are guessing? “)
a = a – 1
if int(g) == x :
print (“Congratulations, you found the correct number. (✧ω✧)”)
print (“Thanks for playing!!! \(^▽^)/”)
sys.exit()
if a == 4:
print (“You have four attempts remaining”)
elif a == 3:
print (“You have three attempts remaining”)
elif a == 2:
print (“You have two attempts remaining”)
elif a == 1:
print (“You have one attempt remaining”)
elif a == 0:
print (“Game Over. (╯°□°)╯︵ ┻━┻”)
print (“The generated number was “,g)
print (“Thanks for playing”)
sys.exit()
if int(g) < (x – 10):
print (“Too low, please try again.”)
if int(g) > x and int(g) <= x + 9:
print (“You are close. Go lower”)
if int(g) > x + 10:
print (“Too high, please try again.”)
if int(g) < x and int(g) >= x – 9:
print (“You are close. Go higher.”)