due on Sunday, 10/4 before 11:59 PM
Sue Evans & James MacGlashan
Hit the space bar for the next slide
This assignment requires much more user input than prior assignments.
<MAJOR-CODE> <COURSE-NUMBER>
CMSC 201
After reading all of the input from the user, you need to output the requirements the user still needs to complete for the degree for each of the parts A - F.
Part <X> Requirements
You have satisified the Part <X> Requirements
You need to take CMSC 441
You need to take MATH 221
You need to take STAT 355 or STAT 451
For Part D, a student has a choice of classes to take, thus, your program output is going to be more complex. There are two halves to Part D:
For the first half you should list all the possible remaining combinations of the six courses. So if a student has already taken BIOL 100, your program would output:
Part D Requirements: You need to take BIOL 301 OR You need to take CHEM 101 AND CHEM 102 OR You need to take PHYS 121 and PHYS 122
For the second half, if the user has not completed 12 science credits, you should print the number of science credits the user has already earned and then just print out the list of classes the user can choose from:
You currently have 4 science credits. You need to have 12 total science credits taken from the following list: BIOL 100 BIOL 100L BIOL 251 BIOL 251L BIOL 252 BIOL 252L BIOL 275 BIOL 275L BIOL 301 BIOL 302 BIOL 302L BIOL 303 BIOL 303L BIOL 304 BIOL 304L BIOL 305 BIOL 305L CHEM 101 CHEM 102 CHEM 102L GES 110 GES 111 GES 120 PHYS 121 PHYS 122 PHYS 122L PHYS 340L
For Part E, a student again has a choice of classes to take.
Part E Requirements: You need to take 1 class(es) from the following list: CMSC 426 CMSC 431 CMSC 435 CMSC 445 CMSC 455 CMSC 456 CMSC 461 CMSC 471 CMSC 481 CMSC 483
For Part F, you should check how many classes the user has taken in addition to the two classes in Part E. If the user has taken less than 3 classes:
Part E Requirements: You have satisfied the Part E Requirements Part F Requirements: You need to take 2 more class(es) from the following list or any other 400 level 3-credit course (except CMSC 404 or CMSC 495-499) CMSC 426 CMSC 431 CMSC 435 CMSC 445 CMSC 455 CMSC 456 CMSC 461 CMSC 471 CMSC 483 OR 1 from the CMSC courses described above and 1 from the following list: MATH 430 MATH 452 MATH 475 MATH 481 MATH 483
linuxserver1.cs.umbc.edu[101] python hw4.py Your greeting goes here How many courses in the CS program have you taken? 4 Enter the class in the form: CMSC 201 Enter the class in the form : MATH 151 Enter the class in the form : PHYS 121 Enter the class in the form : CMSC 202 Part A Requirements: You need to take CMSC 203 You need to take CMSC 304 You need to take CMSC 313 You need to take CMSC 331 You need to take CMSC 341 You need to take CMSC 345 You need to take CMSC 411 You need to take CMSC 421 You need to take CMSC 441 Part B Requirements: You need to take MATH 152 You need to take MATH 221 Part C Requirements: You need to take STAT 355 or STAT 451 Part D Requirements: You need to take BIOL 100 AND BIOL 301 OR You need to take CHEM 101 AND CHEM 102 OR You need to take PHYS 122 You currently have 4 science credits. You need to have 12 total science credits taken from the following list: BIOL 100 BIOL 100L BIOL 251 BIOL 251L BIOL 252 BIOL 252L BIOL 275 BIOL 275L BIOL 301 BIOL 302 BIOL 302L BIOL 303 BIOL 303L BIOL 304 BIOL 304L BIOL 305 BIOL 305L CHEM 101 CHEM 102 CHEM 102L GES 110 GES 111 GES 120 PHYS 121 PHYS 122 PHYS 122L PHYS 340L Part E Requirements: You need to take 2 class(es) from the following list: CMSC 426 CMSC 431 CMSC 435 CMSC 445 CMSC 451 CMSC 455 CMSC 456 CMSC 461 CMSC 471 CMSC 481 CMSC 483 Part F Requirements: You need to take 3 more class(es) from the following list or any other 400 level 3-credit course (except CMSC 404 or CMSC 495-499) CMSC 426 CMSC 431 CMSC 435 CMSC 445 CMSC 451 CMSC 455 CMSC 456 CMSC 461 CMSC 471 CMSC 481 CMSC 483 OR 1 from the CMSC courses described above and 2 from the following list: MATH 430 MATH 441 MATH 452 MATH 475 MATH 481 MATH 483
Since this assignment is meant to be practice with string manipulation, you must use strings to hold the class lists. You aren't allowed to use python lists or sets. To search for classes, you should use the find() method of a string.
<source_string>.find(<substring>)
>>> mystring = 'The cat in the hat' >>> mystring.find('cat') 4 >>> mystring.find('noword') -1
To use the find() method:
You should use the following code to get you started.
Except the calls to the functions that print out each part's requirements, it is a full functioning main().
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()
Notes:
if userClasses.find('CMSC 201') == -1: # Code that executes when the student hasn't taken CMSC 201
When you've finished your homework, use the submit command to submit the file.
submit cs201 HW4 hw4.py
Don't forget to watch for the confirmation that submit worked correctly.
Specifically, the confirmation will say:
Submitting hw4.py...OK
If not, try again.
You can check your submission by entering
submitls cs201 HW4
You should see the name of the file that you just submitted,
in this case, hw4.py.