2016-02-11 51 views
-5

我正在做一個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.") 

Original screenshot

+0

什麼是你的代碼? – zondo

+0

你必須提供更多信息。 – PRVS

+1

我投票結束這個問題作爲題外話題,因爲這既不是代碼寫作也不是教程服務 – jonrsharpe

回答

0
grade = int(input("Enter Score:")) 
print "FFFFFDCBAA"[grade//10] if grade >= 0 else "ERROR!!!!" 
+1

你得分110%;-) –

2

我看到三個問題,都在同一行:

elif (num < 60 and <= 0: 
  1. 語法: num < 60 and <= 0是不是一個有效的表達;應該num < 60 and num <= 0

  2. 邏輯:num <= 0是不是你想要的,它應該是num >= 0

  3. 語法:你錯過了一個右括號)

如果你改變這些,它應該工作。

0

你只需要改變你的elif低於60

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 60 > num >= 0: 
      print ("You have an F") 
     else: 
      print("lnvalid Test Score.")