Home > Net >  Why outputs differ between VScode python terminal & Interatcive terminal?
Why outputs differ between VScode python terminal & Interatcive terminal?

Time:02-26

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. enter image description here

to run it. It will be executed in the "TERMINAL":

input prompt

input a number:

42 inputted

hit enter:

result

CodePudding user response:

it is simple

if you write a = input("a : ") in python terminal it get execute see this enter image description here

Also If I copy your code and paste it into the terminal then it looks like this

Image

-> 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}")

  • Related