我正在尝试将用户输入存储为整数,而不将其附加到列表或创建列表。你知道吗
首先,我尝试为每个输入使用5个独立变量(下面的代码),当运行此代码时,它会提供以下内容:
您输入的华氏度是(1、2、3、4、5)
我该怎么去掉那些括号呢?你知道吗
firstFahr = int(input("Please enter a Fahrenheit temperature: "))
secondFahr = int(input("Please enter a Fahrenheit temperature: "))
thirdFahr = int(input("Please enter a third Fahrenheit temperature: "))
fourthFahr = int(input("PLease enter a fourth Fahrenheit temperature: "))
fifthFahr = int(input("Please enter a fifth Fahrenheit temperature: "))
enteredFahrs = firstFahr, secondFahr, thirdFahr, fourthFahr, fifthFahr
print("The fahrenheits you entered are", enteredFahrs)
感谢您的任何帮助,如果这似乎是一个noob问题,道歉,因为我对Python很陌生。你知道吗
这个怎么样:
如果你真的,真的想避免序列,你可以做一个简单的解包:
我怀疑这是真正要求您做的,但是另一种方法是使用生成器表达式来避免完全存储变量。你知道吗
这将解决您的问题:
没有任何列表(也没有括号)。你知道吗
相关问题 更多 >
编程相关推荐