Python Forum
optimize choices in multiple if ---: statements
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
optimize choices in multiple if ---: statements
#2
Put your code into data:

classNum = input()
 
while classNum not in classses:
    print('Please enter 17BE1, 17BE2, 17BE3 or 17BE4.')
    classNum = input()
pathsToExcel = ['/home/pedro/winter2018/17BE/17BEC1/', '/home/pedro/winter2018/17BE/17BEC2/', '/home/pedro/winter2018/17BE/17BEC3/', '/home/pedro/winter2018/17BE/17BEC4/']
resultFiles = ['17BE1W17results.xlsx', '17BE2W17results.xlsx', '17BE3W17results.xlsx', '17BE4W17results.xlsx']
classNums = ['17BE1', '17BE2', '17BE3', '17BE4']
pathXL = pathsToExcel[classNums.index(classNum)]
resultFile = resultFiles[classNums.index(classNum)]
Better yet, use string formatting, since you are just getting strings:

classNum = input()
 
while classNum not in classses:
    print('Please enter 17BE1, 17BE2, 17BE3 or 17BE4.')
    classNum = input()

pathXL = '/home/pedro/winter2018/17BE/{}/'.format(classNum)
resultFile = '{}W17results.xlsx'.format(classNum)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: optimize choices in multiple if ---: statements - by ichabod801 - Dec-23-2018, 01:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create Choices from .ods file columns cspower 3 761 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  How can I multithread to optimize a groupby task: davisc4468 0 786 Jun-30-2023, 02:45 PM
Last Post: davisc4468
  Multiple Loop Statements in a Variable Dexty 1 1,275 May-23-2022, 08:53 AM
Last Post: bowlofred
  do you have an idea to optimize this code[recursion]]? netanelst 4 1,392 May-20-2022, 06:41 PM
Last Post: jefsummers
  Make Random Choices the same [SOLVED] AlphaInc 6 2,064 May-17-2022, 01:43 PM
Last Post: AlphaInc
  Optimization using scipy.optimize KaneBilliot 3 1,991 Nov-30-2021, 08:03 AM
Last Post: Gribouillis
  Using curve_fit to optimize function (TypeError) Laplace12 4 2,655 Aug-30-2021, 11:15 AM
Last Post: Larz60+
  Multiple Or Statements JoeDainton123 8 2,774 Sep-15-2020, 08:14 PM
Last Post: buran
  SyntaxError: multiple statements found while compiling a single statement Kayode_Odeyinka 1 3,084 Mar-12-2020, 05:50 PM
Last Post: micseydel
  is there a way to optimize my checking system? GalaxyCoyote 4 2,840 Oct-13-2019, 09:18 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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