2017-05-03 2 views
-2

Hier ist mein Code:Grund wenn Anweisungen nicht funktioniert - Python

input_score = raw_input("Enter Score: ") 
score = float(input_score) 

if score >= 0.9 and <= 1.0: 
    print "A" 

elif score >= 0.8 and < 0.9: 
    print "B" 

elif score >= 0.7 and < 0.8: 
    print "C" 

elif score >= 0.6 and < 0.7: 
    print "D" 

elif score < 0.6 and >= 0.0: 
    print "F" 

else : 
print "Error" 

Ich halte eine Nachricht auf der Leitung bekommen 4 sagen, dass ich einen Syntaxfehler haben. Ich bin nicht sicher, was ich falsch mache

+1

'wenn Score> = 0,9 und <= 1.0:' =>' wenn Score> = 0,9 und Score <= 1,0: ' –

Antwort

1

Sie müssen score in beiden if score >= 0.9 and score <= 1.0 angeben, z. Dies wird geparst als if (score >= 0.9) and (score <= 1.0) - es würde keinen Sinn machen, if (score >= 0.9) and (<= 1.0) zu schreiben, da der zweite Teil ein separater Ausdruck ist.

+1

Thank you so much ... das hat funktioniert! – Stephan

2

Sie können nicht in Python if score >= 0.9 and <= 1.0: schreiben, da der Punktestand in Ihrem Ausdruck nicht mit 1.0 verglichen wird, sondern nur mit 0.9. Sie könnten stattdessen if score >= 0.9 and score <= 1.0: schreiben. Python tatsächlich können Sie es in einem kürzeren Format schreiben, wie folgt:

if 1.0>= score >= 0.9: 
+1

Ich schätze deine Hilfe .. das hat funktioniert! – Stephan

Verwandte Themen