Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Python Help
-
19-04-2018 7:07pmHi All im working on a project and im about to just give up i cant seem to get this to work.
Is there anyone that can help Im very new to python.
import random
import sys
def inputNumber(message):
while True:
try:
userinput = int(input(message))
except ValueError:
print("Please enter a valid number Try again.")
continue
else:
return userinput
def continue_question():
continue_question = inputNumber(" Would you like to continue 1 for Yes 2 for No")
if continue_question == 1:
welcome()
else:
print("Goodbye")
sys.exit()
pin,balance,name = [],[],[]
for line in open('bank.txt', 'r').readlines():
columns = line.split()
pin.append(columns[0])
balance.append(columns[1])
name.append(columns[2] + " " + columns[3])
def welcome():
print("Welcome to Banking Management System ")
print("+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+")
print("Please choose from List below")
print()
print()
options =inputNumber("1. Open an account\n2. Close an account\n3. Withdraw money\n4. Deposit money\n5. Generate a report for management\n6. Quit")
if options == 1:
open_account()
elif options == 2:
close_account(pin,balance)
elif options == 3:
withdraw_money(pin,balance)
elif options == 4:
deposit_money(pin,balance)
elif options == 5:
generate_report_management()
elif options == 6:
sys.exit()
def open_account():
acc_number = random.randint(100000, 999999)
if acc_number in pin:
open_account()
acc_name = input("Please enter your Name")
acc_balance = 0
print("You Pin number is ", acc_number)
print("Your balance is ",acc_balance)
print(pin,balance,name)
pin.append(acc_number) # add account number to list
name.append(acc_name) # add account holder name to list
balance.append(acc_balance)#add balance to account
continue_question()
def withdraw_money(pin,balance):
withdraw_from_pin = inputNumber("Please enter Pin for Account you want to withdraw from")
amount_withdraw =inputNumber("Please enter the amount you would like to withdraw ")
pin_call = pin.index(withdraw_from_pin)
current_balance = balance[pin_call]
if amount_withdraw > current_balance:
print("You have do not have funds for this transaction")
else:
new_balance = balance - amount_withdraw
print("your Balance is ", new_balance)
continue_question()
def deposit_money(pin,balance):
deposit_to_pin = inputNumber("Please enter Pin for Account you want to deposit to")
amount_deposit = inputNumber("Please enter the amount you would like to Deposit")
pin_call = pin.index(deposit_to_pin)
current_balance = balance[pin_call]
new_balance = current_balance + amount_deposit
print("Your new balance is ",new_balance)
continue_question()
def close_account(pin,balance):
remove_pin = input("Please enter Pin for Account you want to close ")
pin_call = pin.index(remove_pin)
print("Your account is now closed")
remove_account = pin_call.index.remove[remove_pin]
def generate_report_management():
return
def main():
welcome()
main()0
Comments
-
Not sure if you are using proper indentation as the above does not seem to have any indentation. Python uses indentation to group statements. (Haven't read through the code to check for errors.)
https://docs.python.org/2.0/ref/indentation.html
Regards...jmcc0 -
Without going into it in too much depth
you have an else without an if in inputNumber
where does the block of code beginning with "pin,balance,name = [],[],[]" belong
you never return out of a function, you keep calling the menu. your welcome() menu should be in a loop, select an option, call function, return out to menu, etc.
as said above python makes no sense without indentation.0 -
I have an EDX assignment (Python Beginners course), I've 2 tries and got first one wrong, I've one more correct submission opportunity. Could someone advise me if I'm on the right track, its very short. PM me if available to assist.
Thanks.0 -
Edit: fecking year old post :rolleyes:
OP, you need to use the code tags to make the code appear correctly.import random import sys def inputNumber(message): while True: try: userinput = int(input(message)) except ValueError: print("Please enter a valid number Try again.") continue else: return userinput def continue_question(): continue_question = inputNumber(" Would you like to continue 1 for Yes 2 for No") if continue_question == 1: welcome() else: print("Goodbye") sys.exit() pin,balance,name = [],[],[] for line in open('bank.txt', 'r').readlines(): columns = line.split() pin.append(columns[0]) balance.append(columns[1]) name.append(columns[2] + " " + columns[3]) def welcome(): print("Welcome to Banking Management System ") print("+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+") print("Please choose from List below") print() print() options =inputNumber("1. Open an account\n2. Close an account\n3. Withdraw money\n4. Deposit money\n5. Generate a report for management\n6. Quit") if options == 1: open_account() elif options == 2: close_account(pin,balance) elif options == 3: withdraw_money(pin,balance) elif options == 4: deposit_money(pin,balance) elif options == 5: generate_report_management() elif options == 6: sys.exit() def open_account(): acc_number = random.randint(100000, 999999) if acc_number in pin: open_account() acc_name = input("Please enter your Name") acc_balance = 0 print("You Pin number is ", acc_number) print("Your balance is ",acc_balance) print(pin,balance,name) pin.append(acc_number) # add account number to list name.append(acc_name) # add account holder name to list balance.append(acc_balance)#add balance to account continue_question() def withdraw_money(pin,balance): withdraw_from_pin = inputNumber("Please enter Pin for Account you want to withdraw from") amount_withdraw =inputNumber("Please enter the amount you would like to withdraw ") pin_call = pin.index(withdraw_from_pin) current_balance = balance[pin_call] if amount_withdraw > current_balance: print("You have do not have funds for this transaction") else: new_balance = balance - amount_withdraw print("your Balance is ", new_balance) continue_question() def deposit_money(pin,balance): deposit_to_pin = inputNumber("Please enter Pin for Account you want to deposit to") amount_deposit = inputNumber("Please enter the amount you would like to Deposit") pin_call = pin.index(deposit_to_pin) current_balance = balance[pin_call] new_balance = current_balance + amount_deposit print("Your new balance is ",new_balance) continue_question() def close_account(pin,balance): remove_pin = input("Please enter Pin for Account you want to close ") pin_call = pin.index(remove_pin) print("Your account is now closed") remove_account = pin_call.index.remove[remove_pin] def generate_report_management(): return def main(): welcome() main()
0
Advertisement