我正在做一個python刻字任務。
90
或以上是A
等等等等等字母等級的其餘部分;但是當一個值輸入爲負數時,我需要代碼除了顯示error
之外什麼也不做。python:分級賦值,負值
這是我試過到目前爲止:
#Design a Python program to assign grade to 10 students
#For each student, the program first asks for the user to enter a positive number
#A if the score is greater than or equal to 90
#B if the score is greater than or equal to 80 but less than 90
#C if the score is greater than or equal to 70 but less than 80
#D if the score is greater than or equal to 60 but less than 70
#F is the score is less than 60
#Ihen the program dispalys the letter grade for this student.
#Use while loop to repeat the above grade process for 10 students.
keep_going = 'y'
while keep_going == "y":
num = float(input("Enter a number: "))
if num >= 90:
print("You have an A")
elif num >= 80:
print("You have an 3")
elif num >= 70:
print("You have an C")
elif num >= 60:
print("You have an D")
elif (num < 60 and <= 0:
print ("You have an F")
else:
print("lnvalid Test Score.")
什麼是你的代碼? – zondo
你必須提供更多信息。 – PRVS
我投票結束這個問題作爲題外話題,因爲這既不是代碼寫作也不是教程服務 – jonrsharpe