这是我能编写的最小代码,它复制了我在我的大段代码中遇到的问题,它适用于python 3.4.2
主要问题是我无法正确调用我的函数。 我可以完美地完成程序,但是当我尝试通过再次调用“PrisonCellSize”函数重新启动程序时,输入部分被完全跳过,有没有人知道解决这个问题的方法?我认为,因为我将roomheight和roomize重置为“0”,这将需要用户再次输入?相反,它完全跳过输入部分,它可能与我的意图有关吗?
我对此非常陌生,所以我道歉如果我犯了一个明显的错误,但我在放弃并问你天才之前已经尝试了很长时间的故障排除:PI会感谢任何帮助解决这个问题的Python版本:3.4.2
TLDR;第二次调用时的“PrisonCellSize”函数不会要求用户输入
编辑:格式化,我希望每个人都更清楚
def PrisonCellSize():
global TotalRoomSize
#calculates size of the room
roomheight = 0
roomwidth = 0
roomwidth = float(input("Enter your total room width, make sure it is between 5 and 10 metres:\n"))
roomheight = float(input("Enter the room height, it must be between 1m-4m: \n"))
if ((roomwidth <=10 and roomwidth >=5) and (roomheight <=4 and roomheight >=1)):
print ("Thankyou for your input\n")
else: print ("\nError, please enter the correct amounts")
def NextFunction():
input ("Did you want a window:\n")
def restart():
print ("restarting program\n")
print ("--------------------")
PrisonCellSize()
NextFunction()
restart()
return
#start of program
PrisonCellSize()
NextFunction()
restart()
我的输出如下:
"================================ RESTART ================================
Enter your total room width, make sure it is between 5 and 10 metres:
"8"
Enter the room height, it must be between 1m-4m:
"2"
Thankyou for your input
Did you want a window:
"yes"
restarting program
--------------------
Did you want a window:
"yes"
restarting program
--------------------
Did you want a window:
"yes"
restarting program
--------------------
Did you want a window:"
答案 0 :(得分:0)
def PrisonCellSize():
global TotalRoomSize
#calculates size of the room
roomheight = 0
roomwidth = 0
roomwidth = float(input("Enter your total room width, make sure it is between 5 and 10 metres:\n"))
roomheight = float(input("Enter the room height, it must be between 1m-4m: \n"))
if ((roomwidth <=10 and roomwidth >=5) and (roomheight <=4 and roomheight >=1)):
print ("Thankyou for your input\n")
else: print ("\nError, please enter the correct amounts")
def NextFunction():
input ("Did you want a window:\n")
def restart():
print ("restarting program\n")
print ("--------------------")
PrisonCellSize()
NextFunction()
restart()
return