- 1

I wrote the following program.. But i cant understand if our output is floating value then how to print it.

score1 = int(input()) score2 = int(input()) #your code goes here avg = float((score1 + score2)/2) if avg in range(90,101): print("50") if avg in range(80,90): print("30") if avg in range(70,80): print("10") if avg in range(0,70): print("0") If the input is 67,84 then the avg is 75.1... And my output is blank.. So please help me how i printed output if inserting values avg is float value..

26th Jun 2021, 5:51 AM
Pramod
Pramod - avatar
3 Respuestas
+ 6
import numpy #your code if avg in numpy.arange(90,101,0.5): print("50") if avg in numpy.arange(80,90,0.5): print("30") ... ... ...
26th Jun 2021, 6:21 AM
Simba
Simba - avatar
+ 1
after first if statement, change all if to elif, and no need to last if statement instead just use else statement without any condition
26th Jun 2021, 6:23 AM
Shadoff
Shadoff - avatar
+ 1
""" range() objects cannot be used to test if float values are inside it ^^ to test if a float value is inside a range, rather use comparison operators: """ if 90 <= avg <= 100: print("50") if 80 <= avg < 90: print("30") if 70 <= avg < 80: print("10") if 0 <= 0 < 70: print("0") # but could be simplified as: if avg < 70: print(0) elif avg < 80: print(10) elif avg < 90: print(30) else: print(50)
26th Jun 2021, 7:09 AM
visph
visph - avatar