+ 2

What's wrong on my code that i dont get output?

score1 = int(input()) score2 = int(input()) #your code goes here x= score1 + score2 y= x / 2 if y == range (90,100): print ("50%") elif y == range (80,80): print ("30%") elif y == range (70,79): print ("10%") elif y == range (0,69): print ("0%")

25th Nov 2020, 3:58 PM
Carlos Eduardo Marquez
Carlos Eduardo Marquez - avatar
13 Respostas
+ 8
Use 'in' instead of '==' or better '>' and '<' First condition: if y >= 90: print("50%") Last should just be "else:"
25th Nov 2020, 4:05 PM
Benjamin JĂŒrgens
Benjamin JĂŒrgens - avatar
+ 5
The return type of range func is not int . https://code.sololearn.com/cHNo7HnU618I/#py You can see it prints range(0,4) not the number. So when you compares with y with range () func ,it will always give result false .So the if and elif statement will not work. NotAPyhonNinja has showed how to do that. You can follow that. You can also follow mine: https://code.sololearn.com/c4nFyzUOyDcM/#py
25th Nov 2020, 4:41 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
Now I know the "in" was missing and the == was wrong. I got it to work with the >= and <= but wanted to get it also with the range or correct said in range !!! Thanks a lot you all for your help. It have been a long and frustrating sometimes trip but im getting better at it thanks to all the people that takes the time to help and explain đŸ€— great community here in Sololearn
25th Nov 2020, 6:25 PM
Carlos Eduardo Marquez
Carlos Eduardo Marquez - avatar
+ 1
What about float numbers? I get an error now because some results are float instead of integer. For example 151/2= 75.1... why is this not recognized in the range?
25th Nov 2020, 9:01 PM
Carlos Eduardo Marquez
Carlos Eduardo Marquez - avatar
+ 1
Ðipănjalï like: if y== range int(80,89): Or what do you mean?
27th Nov 2020, 6:16 AM
Carlos Eduardo Marquez
Carlos Eduardo Marquez - avatar
+ 1
Here is the version using range. Also included is some testing. Posting code without testing is always dangerous and a lot of erroneous codes were posted here https://code.sololearn.com/cuI97szeUe8U/?ref=app Important things to note: - Use 101 as upper limit since it is excluded - Use integer division (//). All variables are int. For scores 50 and 51 it will be 50, not 50.5. More important for 90 and 89 it will be 89 and thus "30%", not "50%" - "50%" is the highest result as taken from the original question
27th Nov 2020, 9:00 AM
Benjamin JĂŒrgens
Benjamin JĂŒrgens - avatar
+ 1
If after all the suggestions above the challenge still says you've failed, try removing "%" from your print statements. One of the conditions of the challenge in the Python course was to exclude "%" from your output
27th Nov 2020, 11:09 AM
Jonas Boehn
+ 1
Thank you all, sometimes the challenges have stuff that have been not teached get but with this Q&A page i m filling the holes 👍👍
27th Nov 2020, 11:16 AM
Carlos Eduardo Marquez
Carlos Eduardo Marquez - avatar
0
NotAPythonNinja is it possible to program the float to change to int automatically like: If y = float : Change to int Else: Pass Or something like that i just wake up and I'm using my imagination to solve this đŸ€ŁđŸ€Ł LOL and I'm guessing also that this lines would have to be after the input to be able to work on the results righ?
27th Nov 2020, 5:50 AM
Carlos Eduardo Marquez
Carlos Eduardo Marquez - avatar
- 2
What's wrong on my code that i dont get output? score1 = int(input()) score2 = int(input()) #your code goes here x= score1 + score2 y= x / 2 z=int(y) if z in range (90,100): print ("50%") elif z in range (80,89): print ("30%") elif z in range (70,79): print ("10%") elif z in range (0,69): print ("0%")
27th Nov 2020, 1:25 AM
Michael Oyegunna
Michael Oyegunna - avatar