Python- How to make an if statement between x and y? [duplicate]
Asked Answered
H

1

8

I've recently been breaching out to Python, as C++ is fun and all, but python seems kinda cool. I want to make Python do something as long as the input is between a certain number range.

def main():
    grade = float(input("“What’s your grade?”\n:"))
    if grade >= 90:
        print("“You’re doing great!”")
    elif(78 >= grade <= 89):
        print("“You’re doing good!”")
    elif(77 >= grade > 65):
        print("You need some work")
    else:
        print("Contact your teacher")

main()

The problem arises when I'm making the elif statement, I can't make it so Python only prints the "doing great" statement as long as the grade is between 65 and 89. How would you go about doing ranges of numbers?

Hallel answered 8/11, 2017 at 19:50 Comment(2)
@Frito it's there...Marston
Heh, sorry. I saw it before you updated :-)Awn
G
23

In Python you can do something like this to check whether an variable is within a specific range:

if 78 <= grade <= 89:
    pass
Gipps answered 8/11, 2017 at 19:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.