+ 2
[Solved] What is the default type of the input that we give in python using input() function?
This is my code: def maxnum(a, b): if a >= b: print(a) else: print(b) x = input() y = input() maxnum(x, y) For the input 5 12 I'm getting output as 5 What is the problem?
3 Respuestas
+ 4
The default is a string. So, if you know an extensive amount about computers, "5" is greater than "1" (the first letter) on the ASCII chart. If you want to convert it to an integer, just put int() around your input. For example:
x = int(input())
y = int(input())
+ 3
by default input() is a str, that's why you have to manually convert it to an int by using int(input())
+ 1
Oh, alright.. yeah i knew about the ASCII value but i was thinking it would interpret the type of value here too.
Just like it does in
x = 12
Here it interprets it as int
Thank you for the answer :)