This is only the 2nd program I've ever worked on and I am stuck right off the bat. Our teacher wrote some of the code for us. We just need to call a function for each section of classes, where we remove the spaces between the classes (for example: CMSC 201 CMSC 202 CMSC 301 -- Just remove the spaces between the classes not between CMSC 201.)

LINK to the classes we just need to do A-F: http://www.umbc.edu/catalog/display.php?major=18

import string

def main(): 
 
    # set up course lists 
    requiredList = 'CMSC 201 CMSC 202 CMSC 203 CMSC 304 CMSC 313 CMSC 331 CMSC \
341 CMSC 345 CMSC 411 CMSC 421 CMSC 441' 
    requiredMath = 'MATH 151 MATH 152 MATH 221' 
    mainElectives = 'CMSC 426 CMSC 431 CMSC 435 CMSC 445 CMSC 451 CMSC 455 CMSC\
 456 CMSC 461 CMSC 471 CMSC 481 CMSC 483' 
    optionalMath = 'MATH 430 MATH 441 MATH 452 MATH 475 MATH 481 MATH 483' 
    sci4Cred = 'BIOL 100 CHEM 101 CHEM 102 PHYS 121 PHYS 122' 
    sci3Cred = 'BIOL 301 BIOL 252 BIOL 275 BIOL 302 BIOL 303 BIOL 304 BIOL 305 \
GES 110 GES 111' 
    sci2Cred = 'BIOL 100L BIOL 251L BIOL 252L BIOL 275L BIOL 302L BIOL 303L BIO\
L 304L BIOL 305L CHEM 102L PHYS 122L PHYS 340L'   
 
    userClasses = '' 
 
    numCSReqElectives = 0 
    numCSElectives = 0 
    numReqMath = 0     
    numSciCred = 0 
    numOptMath = 0 
 
    # get the classes the user has taken concatenating them into a list 
    # and counting how many of each type there is 
    numClasses = input("How many courses in the CS program have you taken? ") 
    for i in range(numClasses): 
        uclass = raw_input("Enter the class in the form <MAJOR-CODE> <\
COURSE-NUMBER>: ") 
        userClasses = userClasses + ' ' + uclass 
        if mainElectives.find(uclass) != -1: 
            numCSReqElectives += 1 
        if requiredList.find(uclass) == -1 and mainElectives.find(uclass) == -1\
 and uclass.find('CMSC 4') != -1: 
            if uclass.find('CMSC 404') == -1 and uclass.find('CMSC 495') == -1 \
and uclass.find('CMSC 496') == -1 and uclass.find('CMSC 497') == -1 and uclass.\
find('CMSC 498') == -1 and uclass.find('CMSC 499') == -1: 
                numCSElectives += 1 
        if requiredMath.find(uclass) != -1: 
            numReqMath += 1 
        if optionalMath.find(uclass) != -1: 
            numOptMath += 1 
        if sci4Cred.find(uclass) != -1: 
            numSciCred += 4 
        elif sci3Cred.find(uclass) != -1: 
            numSciCred += 3 
        elif sci2Cred.find(uclass) != -1: 
            numSciCred += 2 
             
    # restrict user to two optional math classes         
    if numOptMath > 2: 
        numOptMath = 2 
  
    # adjust counts for part E & F 
    if numCSReqElectives > 2: 
        numCSElectives += (numCSReqElectives - 2) 
        numCSReqElectives = 2 
         
 
    # call functions to produce output for each part 


main()

here is what I have started on, i started coding it right after function main.

def (requiredList, userClasses):
    print
     print 'You still need to take these classes from Section A          Required Computer Science Courses: '
    print

    # strips spaces between each class in the string
    uclass.rjust(1).strip() # not sure why i have 1 in the parameter but i want to remove 1 space from the end of each class

    # slices every 8 characters each class is 8 characters long
     pos = 
     uclass[pos:pos+8] # I'm not sure how to define pos.

     # then i need to use a the string command .find to find each class that isnt in the string so something like 
    if userClasses.find(uclass) == -1
    print # i dont know what to print or if my if statement is checking the string for each class

I need a lot of help, I understand the logic about 75% on what needs to be done, but only know how to code about 5% of it.

Thanks in advance.

Just remove the spaces between the classes not between CMSC 201

Since these are all in the handy form of abbreviation-space-number, you can just split and combine them in pairs of two. I would suggest a for loop with a step of two to iterate through the resulting list, and combine this element and the next element.

Beware of your indent... Very important in python

print 'one'
     print 'two'   # <== ERROR (one space too much)
    print 'three'

    if condition # < ERROR (missing :  )
    print "four" # < ERROR (missing indent)

Edited 7 Years Ago by jice: n/a

Since these are all in the handy form of abbreviation-space-number, you can just split and combine them in pairs of two. I would suggest a for loop with a step of two to iterate through the resulting list, and combine this element and the next element.

so how would i set the for loop up, and combined everything into 1 string so it can find each class entered in the string, then not print that, using if statements.

This article has been dead for over six months. Start a new discussion instead.