2016-07-24 7 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() 

arbeitet Jedes Mal, wenn ich versuche, es zu laufen, es wird hervorgehoben, dass über „Pause“, wenn ich es löschen, ein weiterer Fehler taucht auf, der "Main()" beim letzten Code ist, "und" macht es weiter ...Ich weiß nicht, was hier los ist, und ich versuchte fast alles, aber es will noch nicht

Ich hoffe, ich kann eine Antwort finden.

+1

Fragen Debuggen Hilfe suchen (** "? Warum nicht dieser Code funktioniert" **) muss das gewünschte Verhalten umfassen, * ein bestimmtes Problem oder Fehler * und * die Kürzester Code erforderlich * um ihn ** in der Frage selbst zu reproduzieren **. Fragen ohne ** eine klare Problemstellung ** sind für andere Leser nicht nützlich. Siehe: [Erstellen eines minimalen, vollständigen und überprüfbaren Beispiels] (http://stackoverflow.com/help/mcve). – MattDMo

Antwort

0

Ich habe Ihren Code funktioniert. Nach dem Aussehen der Dinge bist du neu im Programmieren. Ihr Hauptproblem bestand darin, dass Sie nicht innerhalb einer Funktion auf Variablen zugreifen können, wenn Sie sie nicht als Argumente verwenden. Ich empfehle Ihnen, sich this tutorial anzusehen.

Der Arbeitscode:

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

Ah, vielen Dank, aber muss ich sie jedes Mal zurückgeben? Ich könnte sie zu einer Variablen zugewiesen haben und sie dann mit der Return-Anweisung verwenden. und ja, ich bin neu in der Programmierung, ich habe seit 3 ​​oder 4 Monaten gelernt, weiß ich nicht, aber das Problem ist, ich lerne viele Dinge, Design, und andere Sprachen auch, JavaScript, PHP, Java und Python, also bin ich nicht so professionell, nochmal: vielen Dank für deine Hilfe, ich mag das Programm eigentlich ... –

Verwandte Themen