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!

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
  • I think [this question](https://stackoverflow.com/questions/5424716/how-to-check-if-string-input-is-a-number?answertab=scoredesc#tab-top) is a better duplicate @blhsing – Pranav Hosangadi Jan 09 '23 at 06: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. – Pranav Hosangadi Jan 09 '23 at 06:24

0 Answers0