+ 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?

31st Oct 2020, 8:35 AM
сергей сергей
сергей сергей - avatar
14 odpowiedzi
+ 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
31st Oct 2020, 8:50 AM
777
777 - avatar
+ 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
31st Oct 2020, 9:57 AM
777
777 - avatar
+ 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
31st Oct 2020, 10:54 AM
777
777 - avatar
+ 1
The question is why in one case output 03.2 and in another 3.2
31st Oct 2020, 8:48 AM
сергей сергей
сергей сергей - avatar
+ 1
So the variables a and b are not linked
31st Oct 2020, 8:54 AM
сергей сергей
сергей сергей - avatar
+ 1
Yeah сергей сергей. Why should they be linked?
31st Oct 2020, 9:00 AM
777
777 - avatar
+ 1
Put b=int(input()) Int truncates the 0.
2nd Nov 2020, 3:12 AM
Angry Student(Docvad)
Angry Student(Docvad) - avatar
0
actually they r equal 03.2 === 3.2 i dont know why python return an extra 0 , try google it
31st Oct 2020, 8:58 AM
Med Amine Fh
Med Amine Fh - avatar
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
31st Oct 2020, 9:47 AM
сергей сергей
сергей сергей - avatar
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.
31st Oct 2020, 10:18 AM
сергей сергей
сергей сергей - avatar
0
Maybe so. But if you insert print(a) Then it will display correctly "b" )thanks for the advice
31st Oct 2020, 11:11 AM
сергей сергей
сергей сергей - avatar
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
31st Oct 2020, 8:50 PM
YAKUP KARAKAŞ
YAKUP KARAKAŞ - avatar
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?
31st Oct 2020, 9:10 PM
сергей сергей
сергей сергей - avatar
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.
2nd Nov 2020, 11:53 AM
YAKUP KARAKAŞ
YAKUP KARAKAŞ - avatar