The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 5 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Python
Â
What would I have to add to this code to have it generate 2 numbers instead of one, and also to give the sum of the numbers as a hint for users?
Â
Â
Â
Â
Â
Â
Â
random_number = random.randint(1,10)
tries = 0
tries_remaining = 5
Â
Â
Â
Â
Â
Â
while tries < 5:
guess = input("Guess a random number between 1 and 10. ")
tries += 1
tries_remaining -= 1
Â
Â
Â
try:
guess_num = int(guess)
except:
print("That's not a whole number!")
break
Â
Â
Â
if not guess_num > 0 or not guess_num < 11:
print("That number is not between 1 and 10.")
break
Â
Â
Â
elif guess_num == random_number:
print("Congratulations! You are correct!")
print("It took you {} tries.".format(tries))
break
Â
Â
elif guess_num < random_number:
if tries_remaining > 0:
print("I'm sorry, that number is low. You have {} tries remaining.".format(int(tries_remaining)))
continue
else:
print("Sorry, but my number was {}".format(random_number))
print("You are out of tries. Better luck next time.")
Â
Â
Â
Â
elif guess_num > random_number:
if tries_remaining > 0:
print("I'm sorry, that number is high. You have {} tries remaining.".format(int(tries_remaining)))
continue
else:
print("Sorry, but my number was {}".format(random_number))
print("You are out of tries. Better luck next time.")
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly