+ 3
Why can't I use the input function in the def function in python?
this is the example that we are given: def print_sum_twice(x, y): print(x + y) print(x + y) print_sum_twice(5, 8) why can't I write it this way.. def print_sum_twice(): x = input("give the first number: ") y = input("give the 2nd number: ") print(x+y) print(x+y) print_sum_twice() it give me an error, why?
2 Réponses
+ 5
input is in string type so you must convert it to integer like: x = int(input())
+ 4
In fact, what @Vukan told is true, but it stills should not gives an error as strings can be added.
Did you put two lines as input ? If not, this is why it failed. Sololearn ask for ALL inputs at the beginning of the program