【问题标题】:Type two statements. The first reads user input into person_name. The second reads user input into person_age. Use the int() function to convert键入两个语句。第一个将用户输入读入 person_name。第二个将用户输入读入 person_age。使用 int() 函数进行转换
【发布时间】:2022-11-11 03:40:54
【问题描述】:

[提出的问题]

我已经尝试了所有我学到的方法,但似乎没有什么能给我 zybooks 想要的答案。它要我使用 int() 函数,但每次我运行它时,它都会弹出我无法使用内置函数的错误代码。任何帮助或指导将不胜感激。

【问题讨论】:

  • 请使用tour 并阅读How to Ask。这既不是代码编写也不是教程服务。
  • 我已经尝试了所有我学到的方法向我们展示您尝试过的代码,并向我们展示错误消息。
  • 另外,如果你不能使用“内置函数”,那么我看不出你能做什么任何事物.
  • 它说将字符串转换为 int,因此您可以使用类型转换
  • 同时显示错误。

标签: python


【解决方案1】:

这是一个应该可以工作的sn-p代码。

name = input('Enter Name: ')
age  = int(input('Enter Age: '))

print('Name entered: ', name, 'Age entered: ', age)

我刚试了一下,它存储了名字和年龄。也许您没有将年龄“输入”包装在“int”函数中。

看看是否有帮助。

问候。

【讨论】:

    【解决方案2】:

    人名 = 输入('')

    person_age = int(输入(''))

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案3】:

    键入两个语句。第一个将用户输入读入 person_name。第二个将用户输入读入 person_age。使用 int() 函数将 person_age 转换为整数。如果用户的输入是以下是给定程序的示例输出:Amy 4 5 年后,艾米 9 岁 注意:不要写输入值的提示,使用格式:variable_name = input()

    人名 = 输入()

    年龄 = 输入()

    person_age = int(年龄)

    enter image description here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-15
      • 2021-08-22
      • 1970-01-01
      • 2020-10-29
      • 1970-01-01
      • 2017-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多