python初学者语法语句if elif

python初学者语法语句if elif,python,if-statement,Python,If Statement,我正在学习python,并尝试进行一系列练习,但我被困在下一个练习中: inp_1 = input('your score between 0.0 and 1.0') try: score = float(inp_1) if 0.9 <= score <= 1.0: print ("A") elif score >= 0.8: print ("B") elif score

我正在学习python,并尝试进行一系列练习,但我被困在下一个练习中:

     inp_1 = input('your score between 0.0 and 1.0')

        try:   
score = float(inp_1)   
if 0.9 <= score <= 1.0:
              print ("A")    elif score >= 0.8:
              print ("B")    elif score >= 0.7:
              print ("C")    elif score >= 0.6:
              print ("D")    elif score <  0.6:
              print ("Your grade is an F")    
    else:       
print ('your score is more than 1.0')  
    except:   
 print ('invalid input, please try with a number')
缩进(=每行前面的制表符/空格数)在python中很重要。您发布的代码没有正确缩进。正确的缩进如下所示:

inp_1 = input('your score between 0.0 and 1.0')

try:   
    score = float(inp_1)   
    if 0.9 <= score <= 1.0:
        print ("A")    
    elif score >= 0.8:
        print ("B")
    elif score >= 0.7:
        print ("C")
    elif score >= 0.6:
        print ("D")    
    elif score <  0.6:
        print ("Your grade is an F")    
    else:       
        print ('your score is more than 1.0')  
except:   
    print ('invalid input, please try with a number')
inp_1 = input('your score between 0.0 and 1.0')
try:
    score = float(inp_1)
    if 0.9 <= score <= 1.0:
        print ("A")    
    elif score >= 0.8:
        print ("B")    
    elif score >= 0.7:
        print ("C")    
    elif score >= 0.6:
        print ("D")    
    elif score <  0.6:
        print ("Your grade is an F")
    else:
        print ('your score is more than 1.0')
except:
    print ('invalid input, please try with a number')

这是否回答了您的问题?

您的缩进应该是这样的:

inp_1 = input('your score between 0.0 and 1.0')

try:   
    score = float(inp_1)   
    if 0.9 <= score <= 1.0:
        print ("A")    
    elif score >= 0.8:
        print ("B")
    elif score >= 0.7:
        print ("C")
    elif score >= 0.6:
        print ("D")    
    elif score <  0.6:
        print ("Your grade is an F")    
    else:       
        print ('your score is more than 1.0')  
except:   
    print ('invalid input, please try with a number')
inp_1 = input('your score between 0.0 and 1.0')
try:
    score = float(inp_1)
    if 0.9 <= score <= 1.0:
        print ("A")    
    elif score >= 0.8:
        print ("B")    
    elif score >= 0.7:
        print ("C")    
    elif score >= 0.6:
        print ("D")    
    elif score <  0.6:
        print ("Your grade is an F")
    else:
        print ('your score is more than 1.0')
except:
    print ('invalid input, please try with a number')
inp_1=input('你的分数在0.0到1.0之间')
尝试:
分数=浮动(inp_1)
如果0.9=0.7:
打印(“C”)
elif得分>=0.6:
打印(“D”)
elif评分<0.6:
打印(“你的成绩是F”)
其他:
打印('您的分数超过1.0')
除:
打印('输入无效,请用数字再试')
我想你没有完全理解缩进。这不像其他任何语言。您需要正确地进行缩进


希望它能帮助您,新python用户对缩进感到困惑是正常的,请参阅以修复当前的脚本缩进。