#Hey im just after some help getting the hang of if statements thanks in advance :)
27 messages · Page 1 of 1 (latest)
Since 0.7 > 0.6 the first elif will catch 0.7 and not let it get to the correct elif. Same goes for all of your elif's. You have to organize it so that the least general condition is first and the most general is last.
So you're gonna need to reorganize the elif's in the reverse order that you have them.
"the first elif will catch 0.7 and not let it get to the correct elif." Thanks for reply zach what do you mean by this sorry
The if and all of it's elif's only run up until one of them evaluates to true. So if score is 0.83 this happens
- is 0.83 < 0.6? False
- is 0.83 >= 0.6? True
- print "D"
See how it never gets to the 0.7 check or the 0.8 check?
It stops at the first one that is true.
ahhh okay that makes sense to me
i dont think i made it that far though before aha i was getting this error back
TypeError: '>=' not supported between instances of 'str' and 'float'
but you helped me immensly before i made to it aha
So you gotta do something = float(something)
i think i have assigned float to the variable score but im not to sure now
You haven't. It's all by its lonesome on that line. Which is allowed in Python, just in this case it does nothing.
how could i go about returning the input value and converting into the float
float(score)```
Just assign the return from float to a variable.
So score = float(score)
Just change the one line to have that = bit
how does that get the value from my input though
You put the value from the input into score, float then changes it from a string to a number.
my bad
float doesn't actually change score though, it just returns the number, so to change score you need to reassign it the return from float
score = input("Enter Score: ") # Score is a string
score = float(score) # Score is now a number