Python Forum
If statement with arrays without activating while statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If statement with arrays without activating while statement
#2
Well, you could use the in operator, which sees if any one of the items in a container equals a specific value:

if correct1 in Answer1:
Then you could get rid of the for loop and just have the if/else clause. However, it appears you are only using Answer1 to handle different ways to capitalize 'push walls'. This is generally done with the lower method of the string, which converts it to lower case:

if correct1.lower() == 'push walls':
Your use of global is problematic. You'll run into problems with multiple different variables using slightly different names. You should pass values to the functions as parameters, and get results out of them with return statements. This way you can pass values between functions without clogging the global namespace.

If you want to expand this you are going to have multiple functions doing similar things, and the code is going to be hard to maintain. If you find a problem in one function, you'll have to correct it in all of the similar functions. Much better is to keep the rooms and the information about the rooms in some sort of data structure, and to have functions that can operate on the information for any room, and keep track of where you are in the rooms. See the text adventures tutorial link in my signature for an example of how to do this.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: If statement with arrays without activating while statement - by ichabod801 - Jun-20-2018, 08:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  If statement question help Gatso100 4 760 Jan-09-2024, 11:53 AM
Last Post: Pedroski55
  Can't stop if statement from executing even though False + Messy code? monkeydesu 1 1,045 Oct-17-2022, 05:46 AM
Last Post: deanhystad
  Post IF Statement Input OrphanedSoul 2 2,363 Jun-04-2021, 05:03 PM
Last Post: deanhystad
  if statement not working g0g0g1g 2 1,673 Sep-08-2020, 05:40 PM
Last Post: nilamo
  While statement explanation alkhufu2 3 2,423 Sep-02-2020, 05:46 PM
Last Post: alkhufu2
  I need help to solve this task using while statement rico4pepe 6 9,327 Apr-02-2020, 11:34 AM
Last Post: pyzyx3qwerty
  Filtering with IF Statement Mike2607 10 5,400 Nov-29-2019, 07:18 PM
Last Post: perfringo
  Trying to get an if..elif..else statement to run. Azurato 4 2,699 Jul-29-2019, 12:17 PM
Last Post: ichabod801
  Else Statement Not Working SenkouSimmer 4 3,312 Jul-22-2019, 11:42 AM
Last Post: jefsummers
  Help for newbie with if/else statement that has or statement Shevach 2 2,140 May-08-2019, 09:00 PM
Last Post: Shevach

Forum Jump:

User Panel Messages

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