python: how to use the if statement

if-else type:

# if-else 
num = int(input( " Enter grade! " ))
 if num > 60 :
     print ( " Pass " )
 else :
     print ( " Fail " )

The input read is a string type, which needs to be converted to an int type using int [ num = int(input("input grade!")) ]

if-elif-else type:

# if-elif-else 
num = int(input( " Enter grade! " ))
 if num > 80 :
     print ( " Good " )
 elif num > 60 :
     print ( " Pass " )
 else :
     print ( " Fail " )

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325790821&siteId=291194637