2017-02-23 2 views
-4

Wie kann ich diesen Pseudocode in ein Python-Programm auf einem Geldautomaten verwandeln?Wie verwandelt man diesen Pseudo-Code in ein Python-Programm?

OUTPUT “Menu” 
OUTPUT “1 – Cash withdrawal” 
OUTPUT “2 – Balance” 
OUTPUT “3 – PIN Services” 
OUTPUT “4 – Pay bills” 
OUTPUT “5 – Cancel” 
OUTPUT “Please select an option 1-5:” 
user_option ← USERINPUT 

IF user_option = 1 THEN 
    proc_withdrawal() 
ELSEIF user_option = 2 THEN 
    proc_balance() 
ELSEIF user_option = 3 THEN 
    proc_pin() 
ELSEIF user_option = 2 THEN 
    proc_bills() 
ELSEIF user_option = 2 THEN 
    proc_cancel() 
ELSE 
    OUTPUT “Please only enter an option 1, 2, 3, 4 or 5” 
ENDIF 
+2

Haben Sie versucht, etwas von sich selbst? – Haris

+2

Sie sind in der Nähe. Der nächste Schritt besteht darin, ein elementares Python-Tutorial zu lesen. – DyZ

+0

Möchten Sie diese Funktionen implementieren? Wenn ja, wo steckst du fest? – halfer

Antwort

0

so etwas wie diese versuchen, die Unterschiede zwischen dem psudeo Code notieren und den eigentlichen Code und dass, da Sie die Benutzer Eingang zu einer Reihe vergleichen wollen, müssen Sie die Zeichenfolge Eingabe in einen int konvertieren:

import sys 

def proc_withdrawal(): 
    print("Your proc_withdrawal code goes here") 

def proc_balance(): 
    print("Your proc_balance code goes here") 

def proc_pin(): 
    print("Your proc_pin code goes here") 

def proc_bills(): 
    print("Your proc_bills code goes here") 

def proc_cancel(): 
    print("Thank you for using Simon Raivid's Cash Machine, Have a nice day!") 
    sys.exit(0) 

while True: 
    print("Simon Raivid's Cash Machine") 
    print("===========================") 
    print("\t1 – Cash withdrawal") 
    print("\t2 – Balance") 
    print("\t3 – PIN Services") 
    print("\t4 – Pay bills") 
    print("\t5 – Cancel") 
    user_option = int(input("Please select an option 1-5: ")) 

    if user_option == 1: 
    proc_withdrawal() 
    elif user_option == 2: 
    proc_balance() 
    elif user_option == 3: 
    proc_pin() 
    elif user_option == 4: 
    proc_bills() 
    elif user_option == 5: 
    proc_cancel() 
    else: 
    print("Please only enter an option 1, 2, 3, 4 or 5") 
Verwendung

Beispiel:

Simon Raivid's Cash Machine 
=========================== 
    1 – Cash withdrawal 
    2 – Balance 
    3 – PIN Services 
    4 – Pay bills 
    5 – Cancel 
Please select an option 1-5: 4 
Your proc_bills code goes here! 
Simon Raivid's Cash Machine 
=========================== 
    1 – Cash withdrawal 
    2 – Balance 
    3 – PIN Services 
    4 – Pay bills 
    5 – Cancel 
Please select an option 1-5: 5 
Thank you for using Simon Raivid's Cash Machine, Have a nice day! 
+0

vielen Dank –

Verwandte Themen