Skip to content

Instantly share code, notes, and snippets.

@Mathsmaniac
Created June 27, 2021 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mathsmaniac/4b273b856975638b4e6db181013fdc25 to your computer and use it in GitHub Desktop.
Save Mathsmaniac/4b273b856975638b4e6db181013fdc25 to your computer and use it in GitHub Desktop.
This function gets an input, and if it is a whole number between 1 and 10, it puts the value inuser_balance
"""
Component 1 of Lucky Unicorn
This function gets an input, and if it is a whole number between 1 and 10, it
puts the value in user_balance
Otherwise, it raises errors and tells the user that a invalid input is entered
until a valid input is entered.
Written by Nathan Smith
28/06/21
"""
def check():
print('How much money would you like to play with?')
while True:
user_balance = input('Please enter a whole number from 1-10: ')
try:
user_balance = int(user_balance)
except ValueError:
pass
else:
if 0 < user_balance < 11:
break
else:
pass
check()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment