Python Forum
How to make boolean if's name specific?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make boolean if's name specific?
#1
I am currently taking an AP Computer Science course, and I was doing fine until I came across this assignment. I do not know how to make an if statement for a boolean name specific. I was hoping that someone could help me so that I can just get that part done. I will also include a picture of the assignment so you can see what I mean.
bal = 1000


input("Deposit or Withdrawal?: ")
if "withdrawal":
    withdraw = int(input("How much would you like to withdrawal?: "))
    if withdraw > 1000:
        print "You cannot have a negative balance!"
    elif withdraw < 0:
        print "You cannot withdraw less than zero!"
    else:
        print bal - withdraw
elif "deposit":
    depo = int(input("How much would you like to deposit?: "))
    if depo < 0:
        print "INVALID TRANSACTION: CANNOT DEPOSIT NEGATIVELY"
    else:
        print bal + depo
else:
    print "INVALID CHOICE, CHOOSE EITHER WITHDRAWAL OR DEPOSIT IN ALL LOWERCASE"
Reply
#2
Don't post images, insert the code here with insert python
Reply
#3
compare line 4 and line 6, do you see the difference? You need to bind the user input on line 4 to a name, and then use that name on line 5, e.g.
choice = input("Deposit or Withdrawal?: ") # line 4
if choice == "withdrawal": # line 5


elif choice == "deposit": # line 13
remember it's case-sensitive
also, don't forget to change bal when perform operation (not just print)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

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