使用Python中的Integer值进行可变打印

时间:2015-01-16 00:48:35

标签: python variables

有人可以帮助解决这个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)

1 个答案:

答案 0 :(得分:0)

好的!所以我假设:

  1. 您需要变量为整数
  2. 您需要在while循环中计算音量
  3. 您想要返回用户输入的变量。
  4. 我还假设你使用的是python 2
  5. 这就是你的代码应该是这样的:

    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
    

    希望这有帮助! :)