1
我一直在努力使用「while」命令和循環。我錯過了一個停車點,但我不知道如何創建一個停車點。我試圖創建一個程序來模擬原始股票期權的選擇,但它只是循環前兩個沒有停止點的循環。任何幫助,將不勝感激。無法關閉循環或創建提示進度
selection = " "
while selection not in ("r","R","t","T"):
print("This program can operate in random mode (fluctuations will randomly occur) or it can operate in test mode (fluctuations are fixed).")
print("(r)andom mode")
print("(t)est mode")
selection = input("Mode of operation:")
if selection not in ("r","R","t","T"):
print("\nPlease select 'r' or 't' for mode selection\n")
elif (selection == "r"):
print("Random mode enabled")
n = random.randrange(1,101)
selection = " "
while selection not in ("1","2","3"):
print("\tInvestment options:")
print("(1)Fly-By-Night Investments (FBN): high risk, high potential returns")
print("(2)Blue Chips INC. (BCI): moderate risk, good potential yearly returns")
print("(3)Slow-And-Steady-Corp. (SNS), mature industry stock: no risk but low returns")
selection = input("Please enter your investment option 1, 2, or 3:")
if selection not in ("1","2","3"):
print("\nPlease enter an investment option from the menu using 1, 2, or 3 as valid selections:\n")
隨機和測試模式後來在節目中來了,但我想證明,我沒有一個停車點的任何位置的循環。它只是循環兩個。
在ifs中使用「break」 – sqram 2013-03-01 03:55:39