【发布时间】:2022-01-28 15:50:21
【问题描述】:
我在 VScode 上运行此代码。
age_1 = int(input("age : "))
print(age_1)
它在终端输出中显示:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'print(age_1)
在 Pycharm 中,它在输入为 12 后显示此输出:
age : 12
12
在 PyShell 中,它的工作方式与 Pycharm 类似。我在 VScode 中做错了什么?
更新: 在 VScode 上的新文件上运行时,它可以像 Pycharm 一样正常运行。但只是一次。然后它每次运行时都会显示与以前相同的错误以及一些新的错误。
这是第一次运行时在 VScode 中正确的一个。
PS I:\CSE\LEARNING\PYTHON 3.0\practice> & "C:/Users/Alvi Adhikary Niloy/AppData/Local/Programs/Python/Python39/python.exe" "i:/CSE/LEARNING/PYTHON 3.0/practice/tempCodeRunnerFile.py"
age : 12
12
这是另一次运行时出现的错误。
& "C:/Users/Alvi Adhikary Niloy/AppData/Local/Programs/Python/Python39/python.exe" "i:/CSE/LEARNING/PYTHON 3.0/practice/tempCodeRunnerFile.py"
File "<stdin>", line 1
& "C:/Users/Alvi Adhikary Niloy/AppData/Local/Programs/Python/Python39/python.exe" "i:/CSE/LEARNING/PYTHON 3.0/practice/tempCodeRunnerFile.py"
^
SyntaxError: invalid syntax
这是另一个错误:
>>>print(age_1) age1 = int(input("age : "))
File "<stdin>", line 1
print(age_1) age1 = int(input("age : "))
^
SyntaxError: invalid syntax
& 这是最后一个。
>>> print(age1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'age1' is not defined
P.S.我不擅长编码。不胜感激,耐心解释一些代码。
【问题讨论】:
标签: python visual-studio-code pycharm