-4

This is what I'm trying to do:

age = input("What is your age?")
if age in range (18,30):
      print("You are young")
else:
      print("You are old")

What's wrong here? How do I do this range thing properly?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Gui
  • 3
  • 1

1 Answers1

0

As Devesh said, you need to cast age as an integer by using int(age). Furthermore, there is a space between range and (18,30) which shouldn't exist. Change it into:

age = int(input("What is your age?"))
if age in range(18,30):
      print("You are young")
else:
      print("You are old")
  • 1
    input less than 18 will print `You are old` – Shubham May 18 '19 at 17:05
  • 1
    Yes but since the input was not sanitized (the user could enter negative numbers of even letters and special characters), this is not the only thing which should be fixed but this is another problem – Sam The Sid May 18 '19 at 17:10
  • This is what I'm doing : income = int(input("What is your annual gross income?")) age = int(input("What is your age?")) if age in range(18,30): if income in range (70000, **this is where I want to put infinite**): print("You are eligible for a loan!") else: print("Sorry, you are not eligible for a loan.") Is there a way I can represent infinity here? – Gui May 18 '19 at 17:34
  • You're looking for float('int') – Sam The Sid May 18 '19 at 17:38