Python Forum
My code doesn't work. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: My code doesn't work. (/thread-1650.html)



My code doesn't work. - Loueegee - Jan-18-2017

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



RE: My code doesn't work. - j.crater - Jan-18-2017

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.


RE: My code doesn't work. - Larz60+ - Jan-18-2017

see: https://python-forum.io/misc.php?action=help&hid=19


RE: My code doesn't work. - Loueegee - Jan-20-2017

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



RE: My code doesn't work. - buran - Jan-20-2017

Add CODE tags and full traceback


RE: My code doesn't work. - wavic - Jan-20-2017

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.



RE: My code doesn't work. - Windspar - Jan-20-2017

wavic answer while I was typing.