+ 1
Please explain level 7 question only
I first wrote the code x = input() print("You entered: " + x) Suppose one entered 8 Result was - You entered: 8 But when i changed code to x = input(int()) print("You entered: " + x) It came 0You entered: 8 Can anyone explain?
5 ответов
+ 3
x = input()
print(type(x))
print(help(int()))
+ 2
Same answer than what I replied in the other Q&A. https://www.sololearn.com/Discuss/3010045/?ref=app
It is due to execution order. The code in the deepest parenthesis is running first in our case.
int(input()) : input() runs first and prompt the user to enter a value, then turns the input into an integer.
input(int()) : int() runs first and because nothing is mentioned inside the parenthesis, it automatically generate an integer with the value 0 then finally run input().
The reason why 0 is printed is because input() basically prints what is inside its parenthesis while waiting for user to enter a value.
+ 1
Just messing with the codes of excercise 14.1 python for beginners
+ 1
Anything as argument to function input() is just displayed on the console. It's helpful for display information about asking input()
like :
name = input( "Enter your Name")
s = input("Enter a string")
n = int( input(" Enter a number")) #if you are taking a number, you need to type cast to int ..
age = int( input())
try these tests and print input and see output..
Hope it helps..
0
print(int()) #returns 0 , if no argument to int(), it returns 0, which is given as argument to input() , and it's just displayed on console..
what are you actually trying!?