Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My code doesn't work.
#1
My code is supposed to display options after you enter a choice but it doesn't.

bank = 50000
password = "Heil"
weapon_imports = ("3 RPGS, 30 AK47s, 12 Dragunov Snipers, 300lbs of C4 plastic explosive")
admin_access = 0
access_id = 0
print("This is you're bank speaking. We need to make sure we have all of our clients updated information. I just need you to tell me a few things.")
x = input("Enter you're credit card number")
y = input("Enter you're cvv number")
z = input("Enter you're expiry date")
print("Thanks for you're time, have a nice day")
if int(x) == 42069360 and  int(y) == 334 and z == "22/6/2018":
  print ("Its ya boii".upper())
access_id = access_id+1
if access_id == 1:
  admin_access = 1
if admin_access == 1:
  print("Greetings, Admin. How can i help you today?")
a = ("Nuclear Launch Codes")
b = ("List of weapon imports")
c = ("Withdrawl")
d = ("Deposit")
choice = input("Enter your choice: A,B,C or D:")
if choice.lower() != "a" and choice.lower() != "b" and choice.lower() != "c" and choice.lower() != "d":
  print("Your choice is", choice)
  if choice == a:
    launch_codes=input("Enter the password for the launch codes")
  if launch_codes == password:
    print("Here are your launch codes for platform Thor. EWHBFDR9XZG")
  if choice == b: 
    print("Here are the list of weapon imports in the last week",weapon_imports)
  if choice == c:
    withdrawl=input("How much would you like to withdrawl?")
    withdrawl = bank-withdrawl
  if choice == d:
    deposit=input("How much would you like to deposit")
    deposit = bank + deposit
Reply
#2
Hello and welcome to the forum!
Please use code tags to make your post/code more readable, you can edit the current post.
Your if statement:
if choice.lower() != "a" and choice.lower() != "b" and choice.lower() != "c" and choice.lower() != "d":
only gets executed if you enter something that is not a,b,c or d.
Also after fixing this you will probably not get expected results, due to your order of if statements and variables declared (only) within them. You would do better to include also elif/else statements. Take a quick look into some docs on if statements, and you will understand perfectly. =)

P.S.:
It would be better to pick a more descriptive thread title.
Reply
#3
see: https://python-forum.io/misc.php?action=help&hid=19
Reply
#4
It still doesn't work even with Elif statments


bank = 50000
password = "Heil"
weapon_imports = ("3 RPGS, 30 AK47s, 12 Dragunov Snipers, 300lbs of C4 plastic explosive")
admin_access = 0
access_id = 0
print("This is you're bank speaking. We need to make sure we have all of our clients updated information. I just need you to tell me a few things.")
x = input("Enter you're credit card number")
y = input("Enter you're cvv number")
z = input("Enter you're expiry date")
print("Thanks for you're time, have a nice day")
if int(x) == 42069360 and  int(y) == 334 and z == "22/6/2018":
 print ("Its ya boii".upper())
access_id = access_id+1
if access_id == 1:
 admin_access = 1
if admin_access == 1:
 print("Greetings, Admin. How can i help you today?")
a = ("Nuclear Launch Codes")
b = ("List of weapon imports")
c = ("Withdrawl")
d = ("Deposit")
choice = input("Enter your choice: A,B,C or D:")
if choice.lower() != "a" and choice.lower() != "b" and choice.lower() != "c" and choice.lower() != "d":
 if choice == a:
   launch_codes=input("Enter the password for the launch codes")
 elif launch_codes != password:
   print("Here are your launch codes for platform Thor. EWHBFDR9XZG")
 elif choice == b: 
   print("Here are the list of weapon imports in the last week",weapon_imports)
 elif choice != c:
   withdrawl=input("How much would you like to withdrawl?")
   withdrawl = bank-withdrawl
 else:
   if choice != d:
     deposit=input("How much would you like to deposit")
   deposit = bank + deposit
Reply
#5
Add CODE tags and full traceback
Reply
#6
You compare two variables - 'choice' and 'a' - if choice == a:.

'a' is a varable with value "Nuclear Launch Codes". You are expecting user input to be the whole string "Nuclear Launch Codes"?

With if choice.lower() != "a" and choice.lower() != "b" and choice.lower() != "c" and choice.lower() != "d": you check if the user input is not a, b, c or d and if it is True why you check against a,b,c,d into the same code block? And you can do it better.

if choice.lower() in 'abcd':
    print("Your choice is", choice)
    if choice.lower == 'a':
        #etc.
    if choice.lower == 'b':
        #etc.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#7
wavic answer while I was typing.
99 percent of computer problems exists between chair and keyboard.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  hi need help to make this code work correctly atulkul1985 5 770 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 675 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 928 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Code works but doesn't give the right results colin_dent 2 709 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Beginner: Code not work when longer list raiviscoding 2 815 May-19-2023, 11:19 AM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,771 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Code used to work 100%, now sometimes works! muzicman0 5 1,427 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  color code doesn't work harryvl 1 882 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  Something the code dont work AlexPython 13 2,228 Oct-17-2022, 08:34 PM
Last Post: AlexPython
  cannot get code to work Led_Zeppelin 10 2,424 Jun-30-2022, 06:28 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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