Python Forum
Else Statement Not Working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Else Statement Not Working
#3
if filename == "class1.txt" or filename == "class2.txt":
But your professor has written, that you don't get credits for this.
Is only class1.txt and class2.txt allowed? Why? If only this two files are
allowed to access, why to write them out instead of using a kind of menu or
command line arguments.

You can use a list or tuple with filenames. Then you can check, if filename is in the iterable.
filename = 'something'
allowed_filenames = ('class1.txt', 'class2.txt')
if filename in allowed_filenames:
    #code

# filename in allowed_filenames returns True, because 'something' is not in the tuple.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
Else Statement Not Working - by SenkouSimmer - Jul-20-2019, 11:24 PM
RE: Else Statement Not Working - by metulburr - Jul-21-2019, 12:28 AM
RE: Else Statement Not Working - by DeaD_EyE - Jul-21-2019, 01:54 AM
RE: Else Statement Not Working - by Yoriz - Jul-21-2019, 11:50 AM
RE: Else Statement Not Working - by jefsummers - Jul-22-2019, 11:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  if statement not working g0g0g1g 2 1,640 Sep-08-2020, 05:40 PM
Last Post: nilamo
  Simple IF statement not working as intended gortexxx 2 2,786 May-17-2018, 07:54 PM
Last Post: gortexxx
  help! if statement not working molliemae 2 2,583 Apr-26-2018, 11:13 PM
Last Post: woooee

Forum Jump:

User Panel Messages

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