Python 中整数值的变量打印
Variable printing with Integer values in 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)
好的!所以我假设:
- 你需要变量是整数
- 你需要在while循环中计算体积
- 您想 return 用户输入的变量。
- 我还假设您使用的是 python 2
您的代码应如下所示:
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
希望这对您有所帮助! :)
有人可以帮忙解决这个 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)
好的!所以我假设:
- 你需要变量是整数
- 你需要在while循环中计算体积
- 您想 return 用户输入的变量。
- 我还假设您使用的是 python 2
您的代码应如下所示:
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
希望这对您有所帮助! :)