1.try-except 2. if 0<=score<=1.0 3. print加引号是为什么

Assignment 3.3
Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error. If the score is between 0.0 and 1.0, print a grade using the following table:

写一个程序来提示0.0和1.0之间的分数。如果分数超出范围,打印一个错误。如果分数在0.0和1.0之间,使用下表打印一个等级。

Score Grade:
'>= 0.9 A'
'>= 0.8 B'
'>= 0.7 C'
'>= 0.6 D'
'< 0.6 F'

If the user enters a value out of range, print a suitable error message and exit.

如果用户输入的数值超出范围,则打印一个合适的错误信息并退出。

input_score = input("Enter Score: ")
try:
    score=float(input_score)//score可能重复时,可以score、input_score
    if 0<=score<=1.0://区间的方法
        if score>=0.9:
            print("A")//python 里 print 何时用“”  何时什么都不加??输出字符串时加""  需要赋值运算时不加
        elif score>=0.8:
            print("B")
        elif score>=0.7:
            print("C")
        elif score>=0.6:
            print("D")
        elif score<0.6:
            print("F")
    else:
        print("Please enter a number between[0,1]")
except:
    print("Please enter a number")

posted @ 2022-09-04 21:31  continentliang  阅读(20)  评论(0编辑  收藏  举报