I have this code here:
JavaScript
x
8
1
def maximum():
2
i = int(float(input("What is the maximum value?")))
3
if i < 1.2:
4
return print("ERROR: Maximum should be greater than 1.2"), maximum()
5
else:
6
return i
7
maximum()
8
But it doesn’t let me use numbers between 0-1.9 showing an output of
JavaScript
1
3
1
What is the maximum value?1.2
2
ERROR: Maximum should be greater than 1.2
3
What should I change in the function to allow decimals to be accepted?
Advertisement
Answer
Remove the conversion to an int
, as this will floor your float
.
JavaScript
1
8
1
def maximum():
2
i = float(input("What is the maximum value?"))
3
if i < 1.2:
4
return print("ERROR: Maximum should be greater than 1.2"), maximum()
5
else:
6
return i
7
maximum()
8