def hourstominutes(minutes):
hours = minutes/60
return hours
h = int(input(print("Enter the number of minutes:")))
print(hourstominutes(h))
Asked
Active
Viewed 61 times
2
Vitaliy Terziev
- 5,818
- 3
- 16
- 24
Sanju Gautam
- 21
- 2
-
6Why are you calling `print()` inside `input()`? The argument to `input()` is a string to print as the prompt. – Barmar Sep 24 '19 at 20:49
-
What is the output that you're getting? – rassar Sep 24 '19 at 20:49
-
3`input` takes a string and prints it to the screen then waits for input. `print` prints to the screen and doesn't return anything, that is, it returns `None`, which then `input` prints. Yes, input does 2 things instead of 1. – solarc Sep 24 '19 at 20:51
-
Thanks @Barmar it's working fine now :) – Sanju Gautam Sep 24 '19 at 20:53
-
Thanks everyone for the help. I understood the difference. – Sanju Gautam Sep 24 '19 at 20:55
2 Answers
4
Because you are adding the function print() within your input code, which is creating a None first, followed by the user input. Here is the solution:
def hours_to_minutes(minutes):
hours = minutes/60
return hours
h = int(input("Enter the number of minutes: "))
print(hours_to_minutes(h))
Output:
Enter the number of minutes: 50
0.8333333333333334
Error - Syntactical Remorse
- 6,969
- 4
- 19
- 42
Celius Stingher
- 14,458
- 5
- 18
- 47
0
Input is printing the result of print("Enter the number of minutes:", and print() returns None. What you want is int(input("Enter the number of minutes:")) with no print().
Aaron Bentley
- 1,219
- 8
- 14