Python Forum
I have two Same Code but One of them Doesnt Work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have two Same Code but One of them Doesnt Work
#1
Hello everyone.. I have a problem
I have two Same Code but One of them Doesnt Work

This is the one that doesnt work
balance=1000
## 1= BALANCE CHECK
## 2= deposit money
## 3= withdraw money
## q= exit
while True:
     operation= input("Choose Operation:")

    if (operation == "q"):
        print("signing out...")
        break
    elif (operation == "1"):
        print("current balance: ",balance)
    elif (operation == "2"):
        money = int(input("amount deposited: "))
        balance += money
        print("current balance: ",balance)

    elif (operation == "3"):
        money = int(input("the amount you want to withdraw: ")
        if (balance-money<0):
            print("You dont have enough money")
            continue
        balance -= money
    else:
        print("Invalid operation, (choose 1,2 or 3")
but this code is working even though both are same

balance=1000
## 1= BALANCE CHECK
## 2= deposit money
## 3= withdraw money
## q= exit
while True:
    operation = input("Choose Operation:")

    if (operation == "q"):
        print("signing out...")
        break
    elif (operation == "1"):
        print("current balance:  ", balance)
    elif (operation == "2"):
        money = int(input("amount deposited:"))
        balance += money
        print("current balance: ", balance)

    elif (operation == "3"):
        money = int(input("the amount you want to withdraw:"))
        if (balance - money < 0):
            print("You dont have enough money")
            continue
        balance -= money

    else:
        print("Invalid operation, (choose 1,2 or 3")
Please help me ...... Angry
I've been working for hours for this.
Reply
#2
You're missing a closing parentheses on line 20.

Your traceback should have pointed you to the area with the bug. Take a look and see what it says before you fix it. Wink
beginner721 likes this post
Reply
#3
As it is now, we have to guess what is not working. Can you describe how they perform differently? Does one have a syntax error (which you should include), or do they both run. If they both run, what are the inputs that show the difference?

Line 7 on the first one is has a different indentation from the later portions which prevents it from running. But I'm not sure if that's your real problem or just a typo from when you pasted it in.
beginner721 likes this post
Reply
#4
There is also an indentation error in line 7.

This should not be a comment.
## 1= BALANCE CHECK
## 2= deposit money
## 3= withdraw money
## q= exit
It should be code.
balance=1000
while True:
    print("1= BALANCE CHECK\n2= deposit money\n3= withdraw money\nq= exit")
    operation= input("Choose Operation:")
 
    if (operation == "q"):
        print("signing out...")
        break
    elif (operation == "1"):
        print("current balance: ",balance)
    elif (operation == "2"):
        money = int(input("amount deposited: "))
        balance += money
        print("current balance: ",balance)
 
    elif (operation == "3"):
        money = int(input("the amount you want to withdraw: "))
        if (balance-money<0):
            print("You dont have enough money")
        else:
            balance -= money
            print("current balance: ",balance)
    else:
        print("Invalid operation")
beginner721 likes this post
Reply
#5
Thanks all of you.
I tried to fix maybe 2 hours but I cant fix.
Maybe I need to rest :)
Thx again.
Reply
#6
Python does a pretty good job pointing out errors. The one place it doesn't do so well is syntax errors, sometimes just saying there is a syntax error on line X. And if your problem is that the line above is missing a closing quote, parenthesis or bracket, Python reports where the problem was identified, not where it occurred.
Reply
#7
(Jan-22-2021, 10:02 PM)deanhystad Wrote: Python does a pretty good job pointing out errors. The one place it doesn't do so well is syntax errors, sometimes just saying there is a syntax error on line X. And if your problem is that the line above is missing a closing quote, parenthesis or bracket, Python reports where the problem was identified, not where it occurred.

Yes, you're right. Python told me the error was "invalid syntax" and target for 21th line.
but 21th line looking good
if (balance - money < 0):
I think I didn't see parentheses for this reason in 20th line
I hope you're understand me, my english not too good :)
Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why doesnt chunk generation work? LotosProgramer 0 248 Jun-18-2021, 01:13 PM
Last Post: LotosProgramer
  if conditions in the for indentation doesnt work ? Sutsro 6 1,317 Jun-15-2021, 11:45 PM
Last Post: bowlofred
  My code doesn't work, can someone help me? aldasrasickas 5 881 Dec-21-2020, 02:26 PM
Last Post: aldasrasickas
  code with exception arguments doen't work MaartenRo 1 675 Aug-09-2020, 06:06 AM
Last Post: Gribouillis
  Line of code to show dictionary doesn't work MaartenRo 2 895 Jul-28-2020, 03:58 PM
Last Post: deanhystad
  code doesnt return anything ofrihemo 3 812 Jun-30-2020, 05:14 PM
Last Post: ofrihemo
  taking input doesnt print as list bntayfur 2 804 Jun-04-2020, 02:48 AM
Last Post: bntayfur
  changing code to work on a batch of images within a folder Afrodizzyjack 2 789 May-12-2020, 08:56 PM
Last Post: Afrodizzyjack
  Cannot Make the python Code work ErnestTBass 4 1,119 Apr-23-2020, 02:42 PM
Last Post: snippsat
  Code used to work, not anymore for no apparent reason? chicagoxjl 1 780 Jan-08-2020, 05:05 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020