我想弄清楚把這個功能分成兩個單獨的功能的最佳方法。一個是Main(),另一個是determineStatus()。我必須使用Main()來調用determinStatus。該代碼正是我想要它做的只是不確定一個有效的方式來分裂它。我想要把這個功能分解成兩個獨立的功能的最佳方式
不太確定一種分解方式而不會出現大量錯誤。
message="How many current credit hours do you have?"
def determineStatus(message):
while True:
try:
userInput = int(input(message))
except ValueError:
print("Please use whole numbers only. Not text nor decimals.")
continue
else:
return userInput
hours = determineStatus(message)
F=30
J=60
S=90
Max=200
if hours <= Max:
if hours < F:
print("You are classified as a Freshman")
if hours > F and hours < J:
print("You are classified as a Sophmore")
if hours >= J and hours < S:
print("You are classified as a Junior")
if hours >= S and hours < Max:
print("You are classified as a Senior")
else:
print("With",hours," hours you are either an Alumni, 2nd Degree seeking student or lying about your hours.")
determineStatus(message)
只要把所有的外部語句中'高清的main():'然後調用'主()' – AChampion
你是什麼意思? @克里斯馬丁 – Yrroth