Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My code doesn't work.
#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


Messages In This Thread
My code doesn't work. - by Loueegee - Jan-18-2017, 11:10 AM
RE: My code doesn't work. - by j.crater - Jan-18-2017, 11:30 AM
RE: My code doesn't work. - by Larz60+ - Jan-18-2017, 12:46 PM
RE: My code doesn't work. - by Loueegee - Jan-20-2017, 01:30 PM
RE: My code doesn't work. - by buran - Jan-20-2017, 01:46 PM
RE: My code doesn't work. - by wavic - Jan-20-2017, 02:17 PM
RE: My code doesn't work. - by Windspar - Jan-20-2017, 02:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I can't for the life of me get this basic If statement code to work CandleType1a 8 116 5 hours ago
Last Post: CandleType1a
  Extending list doesn't work as expected mmhmjanssen 2 238 May-09-2024, 05:39 PM
Last Post: Pedroski55
  hi need help to make this code work correctly atulkul1985 5 886 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 744 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 1,011 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Code works but doesn't give the right results colin_dent 2 774 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Beginner: Code not work when longer list raiviscoding 2 888 May-19-2023, 11:19 AM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,931 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Code used to work 100%, now sometimes works! muzicman0 5 1,539 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  color code doesn't work harryvl 1 956 Dec-29-2022, 08:59 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