*>反覆循環,提示用戶選擇一個選項,然後在運行/請幫我蟒蛇循環if語句
相應的命令和重複,直到用戶選擇退出。 選項爲:0退出程序; 1來計算 一個特定值的流量; 2計算雷諾數,並繪製預期流量。如果用戶選擇任何其他選項, 該程序必須不斷要求他們選擇一個有效值,直到他們 這樣做。 *
而我< = 3:
i=input (" Please enter a number between 0-3:")
if i==0:
print " program will exit."
break
elif i==1:
print (" To calculate flow rate please input these values:")
pressure = input (" Please enter pressure drop in pascals: ")
radius = input (" Please enter radius in m: ")
viscosity = input (" Please enter viscosity of liquid in Pa.s: ")
Length= input (" Please enter length in m: ")
Flowrate = (pressure * pi *(radius**4))/ (8 * viscosity * Length)
print " Therefore, flow rate is " , Flowrate
print " Program will run again for user to calculate flow rate..."
elif i==2:
print (" To calculate reynolds number please input these values:")
q=input ("Please enter a value for flow rate in m^3/s")
radius = input (" Please enter radius in m: ")
density=input (" Please enter density in kg/m^3 : ")
viscosity = input (" Please enter viscosity of liquid in Pa.s: ")
Rno=(2*q*radius*density)/(viscosity*pi*radius*radius)
elif i==3:
print " not implemented yet."
else:
print " Program will start again!"
***new edited post***
最近,很多人都錯過了'''在行尾。這個世界發生了一些奇怪的事情。 – Maroun