-3

If the number that the user enters is less than -100 or more than 200 then I want the program to ask them to " Enter a number between -100 and 200" over and over untill they do so. How can I do this?


while r < temp:
    first_year = float(input("What is the first year?"))
    average_temp = float(input("What is the average temputure for the year"))
    if average_temp < -100:
        print  ("Enter a number between -100 and 200")
    if average_temp > 200:
        print ("Enter a number between -100 and 200)
    if averaget_temp <200:
        print ("The average temputure for year" , first_year , "is" , average_temp)
    if average_temp > -100:
            print ("The average temputure for year" , first_year , "is" , average_temp)

    r += 1
Kevin
  • 3
  • 2

3 Answers3

0

You can make a loop with while.

condition = True
while condition:
    # do_something
    condition = False
3UqU57GnaX
  • 389
  • 3
  • 12
0

You can use the while loop:

while True:
    average_temp = int(input('Number: '))
    if 200 > average_temp > -100:
        break # <----------------- See flow diagram: tutorialspoint.com/python/python_break_statement
    else:
        print('Enter a number between -100 and 200!')
Sigve Karolius
  • 1,356
  • 10
  • 26
inosível
  • 21
  • 1
  • 1
  • 4
0

One example:

number = float(input("Enter a number between -100 and 200: "))
while number<-100 or number>200:
    number = float(input("Enter a number between -100 and 200: "))
print ("Thank you")
YusufUMS
  • 1,506
  • 1
  • 12
  • 24