gpt4 book ai didi

python - 在 Ubuntu Linux 上运行一个 python 文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:49:55 26 4
gpt4 key购买 nike

每次我尝试在终端中运行我的 python 代码时,我总是得到这样的结果,

Hello World
Enter your name: Tyler
Traceback (most recent call last):
File "HelloWorld.py", line 3, in <module>
name = input('Enter your name: ')
File "<string>", line 1, in <module>
NameError: name 'Tyler' is not defined

我是 Python 的新手所以请原谅我,我通常用 c# 编程但是 Windows 坏了所以我正在尝试学习 python。

这是我的代码:

print('Hello World')

name = input('Enter your name: ')

print('Hi', name)

age = input('Enter your age: ')

age = int(age)

if (age == 35):
print('You are as old as Derek Banas')
if (age == 19):
print('You are the same age as me!')
else:
print('You are a different age than me')

print('Hello', name, 'You are', age, "It's nice to see you again!")

最佳答案

您应该使用 raw_input 而不是 input

关于python - 在 Ubuntu Linux 上运行一个 python 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34757571/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com