+ 1
Why in code b = 0.1 * 2 ** 5 print (b) result is 3.2 and in code a = input (int ()) b = 0.1 * 2 ** 5 print (b) result 03.2?
14 Réponses
+ 6
1) Try running,
a = input("some input")
2) int() initializes a 0 value
So, a = input(int())
prints an extra 0 before the actual output i.e., 3.2
+ 3
сергей сергей - I think you're getting confused. The value of `a` isn't affecting value of `b`, but the input function is printing the argument, i.e., int() constructor which returns 0, which is given.
If you'll do,
>>> a = input("enter")
b = 0.1 * 2 ** 5
print(b)
Then, output will be
>>> enter3.2
+ 2
The first line is wrongly typed, it should be
a = int(input( ))
# now you'll get the same result
p.s. - exponentiation isn't a problem here, btw
+ 1
The question is why in one case output 03.2 and in another 3.2
+ 1
So the variables a and b are not linked
+ 1
Yeah сергей сергей. Why should they be linked?
+ 1
Put
b=int(input())
Int truncates the 0.
0
actually they r equal 03.2 === 3.2
i dont know why python return an extra 0 , try google it
0
So what's the question why the value of variable a affects the output format b. They seem to be in no way connected
0
Solved the problem of "exponentiation" here, entered a = input (int ())
b = 0.01 * 2 ** 30
print (b), counted correctly, only the front was 0 and the answer was not accepted. I commented out the first line and everything worked out that is why such a question arose. I know that the first line is not necessary.
0
Maybe so. But if you insert print(a) Then it will display correctly "b" )thanks for the advice
0
actually why do you use a = input(int()) instead of correct use as a = int(input())
and a has no effect on the running code by the way
0
Yakur Wrong got an unexpected result. You can run a = input (int ("5"))
b = 0.01 * 2 ** 2
print (b) and what does it output?
0
сергей сергей
“””
Yakur Wrong got an unexpected result. You can run a = input (int ("5"))
b = 0.01 * 2 ** 2
print (b) and what does it output?
“””
Sergey your problem is what does interpreter in here. if you use visual studio code or pycharm, then you will see this result:
1- (wrong typing in code)
a = input(int())
b = 0.001 * 2 ** 2
print(b)
output:
0
0.004
2- (true typing in code)
a = int(input())
b = 0.001 * 2 ** 2
print(b)
output:
(whatever you give for input in this line)
0.004
conclusion: the wrong type for “a” input gives you a false value “0” or “0” > “None” I think so. and the interpreter in here doesn’t give it a new line and printing it united as 0+0.004 > 00.004
if you use interpreter at computer then you will see the result.
I hope it help.