I was runing this code on VScode :
a = input("a : ")
b = int(a) 2
print(f"a:{a},b:{b}")
The output on Python terminal:
a : b = int(a) 2
>>> print(f"a:{a},b:{b}")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
The Output on Interactive terminal for input 12 :
a:12,b:14
What's the problem here ?
P.S. A similar terminal problem is in this thread but still without any solution.
to run it. It will be executed in the "TERMINAL":
input a number:
hit enter:
CodePudding user response:
it is simple
if you write a = input("a : ")
in python terminal it get execute see this
Also If I copy your code and paste it into the terminal then it looks like this
-> If you see in this image here b = int(a) 2 take as the input of a. Therefore you get error
b is not defined
Conclusion
As you write a = input("a : ")
you need to give the input here example(12)
then write b = int(a) 2
And, Then print(f"a:{a}:b{b}")