Skip to content
← Back to Community
PLEASE HELP ME
Profile icon
Scrooner256

This code won't work, and I have absolutely no idea how to fix it. It is in python, and it is a banking system. You can either take money, add money, check your current balance and invest. PLEASE HELP ME ASAP.

Thanks

Scrooner11

import time
import pandas as pd
import requests_html
from yahoo_fin import stock_info as si
import replit

global balance
balance = 0

print("Welcome to KeildsonBank!")
time.sleep(2)

def menu():
print("|-|-|-|-|-|-|-|-|-|-|-|-|-|-|")
print("| 1. Check Current Balance. |")
print("| 2. Deposit Money. |")
print("| 3. Withdraw Money. |")
print("| 4. Invest. |")
print("| 5. Quit. |")
print("|-|-|-|-|-|-|-|-|-|-|-|-|-|-|")
time.sleep(3)
print("")
global choice
choice = input("Please choose a number: ")
numCheck = ["1", "2", "3", "4", "5"]

while choice not in numCheck:
print("You entered an invalid choice. Please try again")
choice = input("Please choose a number: ")

choice = int(choice)
return choice

def choiceEffect(choice, balance):
while choice == 2:
try:
balance += deposit
except NameError:
print()
try:
balance -= withdrawal
except NameError:
print()
try:
balance -= investment
except NameError:
print()
global deposit
deposit = input("How much money would you like to deposit: ")
while deposit != float:
try:
deposit = float(deposit)
break
except ValueError:
print("You've entered an invalid number. Please try again")
deposit = input("How much money would you like to deposit: ")
balance = balance + deposit
balance = str(balance)
print("You have $" + balance + " left in your balance now.")
balance = float(balance)
return deposit
return balance
break

while choice == 3:
try:
balance += deposit
except NameError:
print()
try:
balance -= withdrawal
except NameError:
print()
try:
balance -= investment
except NameError:
print()
global withdrawal
withdrawal = input("How much money would you like to withdraw: ")
while withdrawal != float:
try:
withdrawal = float(withdrawal)
break
except ValueError:
print("You've entered an invalid number. Please try again")
withdrawal = input("How much money would you like to withdraw: ")
if balance > withdrawal:
balance -= withdrawal
break
elif balance < withdrawal:
print("You are withdrawing too much. You don't have enough money in your balance")
break

while choice == 1:
try:
balance += deposit
except NameError:
print()
try:
balance -= withdrawal
except NameError:
print()
try:
balance -= investment
except NameError:
print()
balance = str(balance)
print("Your current balance is $" + balance)
balance = float(balance)
return balance
break

while choice == 4:
try:
balance += deposit
except NameError:
print()
try:
balance -= withdrawal
except NameError:
print()
try:
balance -= investment
except NameError:
print()

break

def repeatAction(choiceEffect, choice, balance, menu):
choiceEffect(choice, balance)
menu()

menu()

while choice == 1 or choice == 2 or choice == 3 or choice == 4:
repeatAction(choiceEffect, choice, balance, menu)

if choice == 5:
print("Put End Message Here")
else:
print("Holder")

Voters
Profile icon
Scrooner256
Comments
hotnewtop
Profile icon
Scrooner256

It just says this when I run it: File "main.py", line 48
global deposit
^
SyntaxError: name 'deposit' is used prior to global declarat
ion

Profile icon
Raphtalia

@Scrooner256 you need to define deposit before that line. you defined it a few lines after that.

Profile icon
Scrooner256

@Raphtalia thank you!

Profile icon
NirvanaMorradi

@Raphtalia hi.i need your help for the same issue I had ..