Make sure you have already read my post “Super Duper Cool Game” before reading this post!
We have some other functions in this update:
- Longer title: the length of the hyphen of the title is turned into 32 from 16;
- Automatic game ending: when the range is 0 (for example, 16~16), the game is stopped.
- Lower “Yes”: All kinds of “yes” (for example, “YES” or “yEs”) are ok at restarting.
The other rules are still the same. Have fun :^)
import random
answer = random.randint(1, 100)
min_val = 1
max_val = 100
print(‘—————-Number Bomb Game—————-‘)
while True:
try:
enter = int(input(‘Pls enter your number between ‘ + str(min_val) + ‘ and ‘ + str(max_val) + ‘ :’))
if enter max_val:
print(‘That number is illegal. Pls enter another one.’)
continue
elif enter == answer or min_val == max_val:
if enter == answer:
print(‘You have guess the bomb. Game over. You lose.’)
else:
print(‘The range is the smallest. Game over. You lose.’)
enter = input(‘Enter “yes” to play again or enter anything else to exit:’)
if enter.lower() != ‘yes’:
break
answer = random.randint(1, 100)
min_val = 1
max_val = 100
print(‘—————-Number Bomb Game Restarting—————-‘)
else:
if enter > answer:
max_val = enter – 1
else:
min_val = enter + 1
enter = random.randint(min_val, max_val)
print(‘The robot had guessed’ + enter + ‘.’)
if enter == answer or min_val == max_val:
if enter == answer:
print(‘The robot have guess the bomb. Game over. You won.’)
else:
print(‘The range is the smallest. Game over. You won.’)
enter = input(‘Enter “yes” to play again or enter anything else to exit:’)
if enter.lower() != ‘yes’:
break
print(‘—————-Number Bomb Game Restarting—————-‘)
answer = random.randint(1, 100)
min_val = 1
max_val = 100
else:
if enter > answer:
max_val = enter – 1
else:
min_val = enter + 1
except ValueError:
print(“That’s not an integer. Pls enter an integer.”)