0

why i us: a=float(input()) a=a+10 print(a) is correct but when i use a=a+10 a=float(input()) print=(a) is wrong. I need a answer

pls help me

18th Oct 2024, 2:15 PM
Dang Yuh
Dang Yuh - avatar
4 Antworten
+ 6
Dang Yuh , when using (solely) the second code there are 2 other issues: a=a+10 # creates a NameError since variable a is not defined print=(a) # does not output anything, it overwrites the built-in print() function by making it a variable.
18th Oct 2024, 4:01 PM
Lothar
Lothar - avatar
+ 4
Dang Yuh as Lothar said, you can't start with a += 10 or a = a + 10 this will give you a name error because you are modifying a before it is declared. In your code, a is declared in a = float(input()) it should be placed at the top, before you perform any operation on on it.
18th Oct 2024, 11:20 PM
Bob_Li
Bob_Li - avatar
+ 2
a=float(input()) a=a+10 print(a) a=a+10 a=float(input()) print=(a) In the first case, you are asking for input and setting that to a. Then adding ten to that. In the second case you are adding 10 to a, but then setting a to the input, thus replacing whatever was in a.
18th Oct 2024, 2:50 PM
Jerry Hobby
Jerry Hobby - avatar
0
tks guys
19th Oct 2024, 11:30 AM
Dang Yuh
Dang Yuh - avatar