0

I am building a small terminal game and there is a function gold_room and it's the win for the game. There is a line of code that I have to ensure that a number is typed... But it's really long. Here is the function:

def gold_room(): print("This room is full of gold. How much do you take?") choice = input("> ") if "0" in choice or "1" in choice or "2" in choice or "3" in choice or "4" in choice or "5" in choice or "6" in choice or "7" in choice or "8" in choice or "9" in choice: how_much = int(choice) else: dead("Man, learn to type a number.") if how_much < 50: print("Nice, you're not greedy, you win!") exit(0) else: dead("You greedy bastard!") 

I tried to use range() but I kept getting errors. I'm new to Python and coding in general, so it's an experience for sure. Any help would be great!

2
  • I think this question is a better duplicate @blhsing Commented Jan 9, 2023 at 6:20
  • @Yash that is not what OP wants. OP wants to check if any of 0-9 are present in the user's input. Judging by their remaining code (how_much can be less than or even greater than 50!), they probably just want it to be any integer, in which case your code is limited to only 10. Commented Jan 9, 2023 at 6:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.