-2
print(
"""
__ __ __
| | | | | |
| | | | ___| | ___ ___ _ __ ___ ___
| |/\| |/ _ \ |/ __/ _ \| '_ ` _ \/_ \
\ /\/__/ | (_| (_) | | | | | | __/
\/ \/ \___|_|\___\___/|_| |_| |_|\___|
"""
.strip())
print("\t\t\t\tto the pHinator 9001")
ph = input("\nPlease enter a pH value:")
if ph == "7":
print("\nA pH value of 7 is NEUTRAL")
if "0" < ph < "7":
print("\nA pH value of less than 7 is ACIDIC")
if "14" > ph > "7":
print("\nA pH value of more than 7 is ALKALINE")
if ph < "0":
print("\nAn error occurred. Value must be between 0 and 14")
if ph > "14":
print("\nAn error occurred. Value must be between 0 and 14")
cont = input("\nPress 1 to enter a new value, Press 2 to exit.")
if cont == "1":
(RESTART)
if cont == "2":
input("\n\nPress the enter key to exit.")
exit
這是我第一次嘗試製作一個合適的python程序,並且我已經四處搜尋,但找不到有用的東西答案,我知道如何適用於我的程序,謝謝:)如何通過用戶輸入重新啓動python程序
我已經完成了您的建議,但我的程序沒有出現,不確定發生了什麼。 –
你必須遞歸地做。即if cont == 1應嵌套在func_name()中。還要確保你比較整數而不是字符串。 「14」>「7」沒有意義,因爲這些都是字符串。它應該是14和7而不是「14」和「7」。 cont ==「1」與cont == 1相同 – elephant
@ J.Hogg此外,請確保您最初調用該函數。縮進之外的某處。我將編輯上面的代碼,使其更類似 – elephant