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
#1
My multiple-choice marking program gives me a csv file, which I read in python and then enter in an Excel sheet.

My code for choosing which class looks clumsy, but works. I feel there must be a more elegant way to do this. Could you give me any suggestions, please?

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']
if classNum == '17BE1':
        pathXL = pathsToExcel[0]
if classNum == '17BE2':
        pathXL = pathsToExcel[1]
if classNum == '17BE3':
        pathXL = pathsToExcel[2]
if classNum == '17BE4':
        pathXL = pathsToExcel[3]

if classNum == '17BE1':
        resultFile = resultFiles[0]
if classNum == '17BE2':
        resultFile = resultFiles[1]
if classNum == '17BE3':
        resultFile = resultFiles[2]
if classNum == '17BE4':
        resultFile = resultFiles[3]
Reply


Messages In This Thread
optimize choices in multiple if ---: statements - by Pedroski55 - Dec-22-2018, 11:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  backtesting can't optimize Running_Code 1 145 May-23-2025, 07:46 PM
Last Post: snippsat
  Create Choices from .ods file columns cspower 3 1,954 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  How can I multithread to optimize a groupby task: davisc4468 0 1,250 Jun-30-2023, 02:45 PM
Last Post: davisc4468
  Multiple Loop Statements in a Variable Dexty 1 1,895 May-23-2022, 08:53 AM
Last Post: bowlofred
  do you have an idea to optimize this code[recursion]]? netanelst 4 2,328 May-20-2022, 06:41 PM
Last Post: jefsummers
  Make Random Choices the same [SOLVED] AlphaInc 6 4,003 May-17-2022, 01:43 PM
Last Post: AlphaInc
  Optimization using scipy.optimize KaneBilliot 3 3,048 Nov-30-2021, 08:03 AM
Last Post: Gribouillis
  Using curve_fit to optimize function (TypeError) Laplace12 4 4,020 Aug-30-2021, 11:15 AM
Last Post: Larz60+
  Multiple Or Statements JoeDainton123 8 4,272 Sep-15-2020, 08:14 PM
Last Post: buran
  SyntaxError: multiple statements found while compiling a single statement Kayode_Odeyinka 1 5,108 Mar-12-2020, 05:50 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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