我抄袭了阿尔·斯威加特在他的第三课视频中给出的代码,让无聊的东西自动化。当我运行这个模块时,我得到了一个错误
分析时
意外的EOF
在最后一行,我试着写
print('You will be " + str(int(MyAge + 1) + " in a year.')
然后,代码将运行,但它不会添加年龄,而是显示字符串:
You will be " + str(int(MyAge + 1) + " in a year.
这个程序会打招呼并询问我的名字:
print ('Hello World!')
print ('What is your name?') # ask for their name
myName = input()
print('It is good to meet you, ' + myName)
print('The length of your name is:')
print(len(myName))
print('What is your age?') #ask for their age
myAge = input()
print('You will be ' + str(int(MyAge + 1) + ' in a year.')
如果用户输入年龄的29
,则输出应为
You will be 30 in a year.
而不是
You will be " + str(int(MyAge + 1) + " in a year.
发布于 2019-06-26 08:27:26
使用以下代码。注意在倒数第二行中使用int,并在最后一行中删除int。
# This program says hello and asks for my name
print ('Hello World!')
print ('What is your name?') # ask for their name
myName = input()
print('It is good to meet you, ' + myName)
print('The length of your name is:')
print(len(myName))
print('What is your age?') #ask for their age
myAge = int(input()) # CASTING TO AN INT ON THIS LINE
print('You will be ' + str(myAge + 1) + ' in a year.') # CHANGING TO A STRING ON THIS
# LINE AND REMOVING THE INT FUNCTION
https://stackoverflow.com/questions/56763489
复制相似问题