0

As you saw by the title, I'm making a guessing game for fun, and ran into the issue of saying something if the input wasn't between 1 and 10 (printing) I tried the thing below, but it just didn't work in general and gave errors:

if guess.isdigit and > 10:
import random
import time
streak = 0
numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]



while True:
  answer = random.choice(numbers)
  insultlist = ["bro the real answer was " + answer + ", how are you even that bad?", "you suck at this, you weren't even close. The correct answer was " + answer + "..", "it's the people like you who make me question the future of this planet. The actual answer was " + answer + ".", "lol u suck, the real answer was " + answer + "."]
  insultchoice = random.choice(insultlist)

  guess = input("Type a number between 1 and 10! ")


  if guess == answer:
    print("lol ur lucky, you guessed it correctly.")
    streak = streak + 1
    streakmsg = f"You're at a streak of {streak}."
    print(streakmsg)
    time.sleep(1)
    print("______________________________________________________")

  else:
    if guess.isdigit():
      print(insultchoice)
      if streak > 0:
        loststreak = f"You lost your streak of {streak}."
        print(loststreak)
        streak = 0
      time.sleep(1)
      print("______________________________________________________")
    else:
      print("That's not even a number..")
      time.sleep(1)
      print("______________________________________________________")
nathan liang
  • 1,000
  • 2
  • 11
  • 22

1 Answers1

1

you can use an if statement to check if it is between 1 and 10 and use and else statement for the code you want to run when its not between 1 and 10

if guess.isdigit():
    guess = int(guess)
    if guess > 0 and guess < 11:
        # code for if it is between 1 and 10
    else:
        # code for if it is not