【问题标题】:Age after 10 years [duplicate]10年后的年龄[重复]
【发布时间】:2020-09-04 11:45:50
【问题描述】:

我正在创建一个程序,我在其中接受用户的输入,即他们的名字、姓氏和年龄。我必须计算10年后的年龄。 我制作的程序是:

name=input("Enter your first name: ")
name1=input("Enter your last name: ")
age=int(input("Enter your age: "))
counter=age+10
print(name + name1 + ", you will be" + counter + " years old in 2030")

首先它显示以下错误:

 print(name + name1 + ", tou will be" + counter + "years old in 2030")
TypeError: can only concatenate str (not "int") to str

比它不打印 10 年后的年龄。 请帮帮我!

【问题讨论】:

  • 你应该在name1name2之间加一个空格,在, tou will be之后加一个空格(以及修正拼写)

标签: python


【解决方案1】:

你必须将 counter 转换为 str:

print(name + name1 + ", you will be" + str(counter) + " years old in 2030")

【讨论】:

    【解决方案2】:
    print(name + name1 + ", you will be" + str(counter) + " years old in 2030")
    

    将其转换为字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-25
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 2021-08-18
      • 2016-03-19
      • 1970-01-01
      相关资源
      最近更新 更多