Python中带整数值的变量打印

2024-04-23 16:47:23 发布

您现在位置:Python中文网/ 问答频道 /正文

有人能帮助解决这个python问题吗?你知道吗

问题: -当变量具有整数值时,我需要同时打印多个变量。你知道吗

如果有帮助的话,我正在尝试制作一个体积计算器,这是为了上下文:

if(custom_answer is True and preset_answer is False):
    custom_length_answer=input("Length=")

    custom_width_answer=input("Width=")

    custom_height_answer=input("Height=")

a=custom_length_answer
b=custom_width_answer
c=custom_height_answer


while custom_answer is True and preset_answer is False:
    print("The volume of your custom measurements is..."int(a*b)*c)

Tags: andanswerfalsetrueinputifiscustom
1条回答
网友
1楼 · 发布于 2024-04-23 16:47:23

好吧!所以我假设:

  1. 你需要变量是整数
  2. 你需要在while循环中计算体积
  3. 您希望返回用户输入的变量。你知道吗
  4. 我还假设您使用的是python2

您的代码应该是这样的:

if (custom_answer == True and preset_answer == False):
    custom_length_answer = a = int(raw_input("Length= ") # assign variable to a and assuring that it is already an integer using the int.
    custom_length_answer = b = int(raw_input("Width= ") # Same as above
    custom_length_answer = c = int(raw_input("Height= ") # Same as above

return a # returning the value of the variables
return b
return c

while custom_answer == True and preset_answer == False: # Your loop
    print("The volume of your custom measurements is:" + a*b*c)
    # some more code

希望这有帮助!:)

相关问题 更多 >