2016-07-24 21 views
-5
import time 
#Initializing Variables 
currentMoney = 0 
depositedMoney = 0 
takenMoney = 0 
#Main Fucntion which shows when the program starts 
def Main(): 
    while True: 
     userChoice = input("Welcome to the ATM Organizer. To Preceed Enter 1 To Close Enter 0") 
     if userChoice == 1: 
      Atm() 
     elif userChoice == 0: 
      print("Thank you.Good Bye!") 
      break 
def Atm(): 
    Handling Invalid Inputs 
    while True: 
     try: 
      atm = int(input("Welcome Inside The ATM , To See your money , Type '1' , To put money to the cash machine , Type '2' , To take money out of the ATM , Type '3' , To Exit the ATM , Type '0' .")) 
     except ValueError: 
      print("You didn't choose what was given!") 
      continue 
    Input Choices 
     if (atm == 0): 
      Main() 
     elif (atm == 1): 
      print("You Have ",currentMoney," Inside your account.") 
      break 
     elif (atm == 2): 
      money = int(input("How Much money do you want to deposit? ")) 
      depositedMoney+=money 
      currentMoney=depositedMoney 
      print("You Have ",currentMoney," Inside Your Account") 
      break 
     elif (atm == 3): 
      while True: 
       takeMoney = int(input("How much money do you want to take? ")) 
       if (takeMoney > currentMoney): 
        print("You don't have that value.") 
        continue 
       else: 
        print("LOADING...") 
        time.sleep(3) 
        takenMoney+=takeMoney 
        print("You've taken ",takenMoney," , You now have "(currentMoney-takenMoney," In your account") 
        break 
Main() 

每當我嘗試運行它時,它突出顯示上面的「break」,當我刪除它時,彈出另一個錯誤,這是最後一個代碼中的「Main()」,並且「它一直這樣做......我不知道這裏有什麼問題,我嘗試了幾乎所有的東西,但它仍然不想工作

我希望我能找到答案。

+1

問題尋求幫助調試(**「?爲什麼不是這個代碼工作」 **)必須包括所期望的行爲,*一個特定的問題或錯誤*和*的在問題本身**中重現它的最短代碼*。沒有**明確問題陳述**的問題對其他讀者沒有用處。請參閱:[如何創建最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 – MattDMo

回答

0

我讓你的代碼工作。從外觀上看,你是編程的新手。您的主要問題是,如果不包含它們作爲參數,則無法從函數內部訪問變量。我建議你看看this tutorial

工作代碼:

import time 
#Initializing Variables 
currentMoney = 0 
depositedMoney = 0 
takenMoney = 0 
#Main Fucntion which shows when the program starts 
def Main(currentMoney, depositedMoney, takenMoney): # arguments were missing 
    while True: 
     try: 
      userChoice = int(input("Welcome to the ATM Organizer. To Preceed Enter 1 To Close Enter 0")) # "int()" was missing. had to add try and except as well 
     except ValueError: 
      print("You didn't choose what was given!") 
      continue 
     if userChoice == 1: 
      currentMoney, depositedMoney, takenMoney = Atm(currentMoney, depositedMoney, takenMoney) # was missing 
     elif userChoice == 0: 
      print("Thank you.Good Bye!") 
      break 
def Atm(currentMoney, depositedMoney, takenMoney): # arguments were missing 
    #Handling Invalid Inputs # comment sign was missing 
    while True: 
     try: 
      atm = int(input("Welcome Inside The ATM , To See your money , Type '1' , To put money to the cash machine , Type '2' , To take money out of the ATM , Type '3' , To Exit the ATM , Type '0' .")) 
     except ValueError: 
      print("You didn't choose what was given!") 
      continue 
    #Input Choices # comment sign was missing 
     if (atm == 0): 
      return currentMoney, depositedMoney, takenMoney # was missing 
     elif (atm == 1): 
      print("You Have ",currentMoney," Inside your account.") 
      return currentMoney, depositedMoney, takenMoney # was missing 
     elif (atm == 2): 
      money = int(input("How Much money do you want to deposit? ")) 
      depositedMoney+=money 
      currentMoney=depositedMoney 
      print("You Have ",currentMoney," Inside Your Account") 
      return currentMoney, depositedMoney, takenMoney # was missing 
     elif (atm == 3): 
      while True: 
       takeMoney = int(input("How much money do you want to take? ")) 
       if (takeMoney > currentMoney): 
        print("You don't have that value.") 
        continue 
       else: 
        print("LOADING...") 
        time.sleep(3) 
        takenMoney+=takeMoney 
        print("You've taken ",takenMoney," , You now have ",(currentMoney-takenMoney)," In your account") # ")" was missing, "," was missing 
        return currentMoney, depositedMoney, takenMoney # was missing 
Main(currentMoney, depositedMoney, takenMoney) # arguments were missing 
+0

啊非常感謝你,但我每次都必須回來嗎?我可以將它們分配給一個變量,然後將它與return語句一起使用。 和是的,我是編程新手,我已經學習了3到4個月,但我不知道,但問題是我學習很多東西,設計和其他語言,JavaScript,PHP,Java和Python,所以我不再那麼專業,非常感謝你的幫助,我實際上很喜歡這個程序。 –

相關問題