I'm to have the user input what classes they have taken and tell them what they have left to do. I have my for loop done but I feel like I need an array or something because they should have entered requirement for 6 different class types. Here is my code, my conditional wont work though, any ideas?

import string

number_of_courses = input ('Please enter...')

for number_of_courses in range (0, number_of_courses):
       major = raw_input('Enter class type') #cmsc, math, etc..
       coursenum = input('Enter course number')

print ("A Requirements") #for cmsc

if major = cmsc: #this wont work, idk why?!?!?
       if coursenum = 201:
             print ('You need 202, 203, 304, 313, 331, 341, 345, 421')

I'm very confused, there must be an easier way to do this than using a million if statements.

I've added some print statements to give a hint about what is being processed

number_of_courses = input ('Number of course to enter... ')

for number_of_courses in range (0, number_of_courses):
    major = raw_input('\nEnter class type ') #cmsc, math, etc..
    coursenum = input('Enter course number ')
    print "input was", major, coursenum

print ("\nA Requirements") #for cmsc
print "comparing", major, coursenum

##-------------  my test  ---------------------------------------
Number of course to enter... 3

Enter class type csmc
Enter course number 101
input was csmc 101

Enter class type math
Enter course number 201
input was math 201

Enter class type junk
Enter course number 301
input was junk 301

A Requirements
comparing junk 301

there must be an easier way to do this than using a million if statements.

Start with a dictionary to store the requirements, etc. which you can then use to look up classes taken. What is left over is what they have yet to take.

if major = cmsc:

should be

if major == cmsc:

I'm very confused, there must be an easier way to do this than using a million if statements.

one solution

if coursenum in [201,202, 203, 304, 313, 331, 341, 345, 421] 
    print '202, 203, 304, 313, 331, 341, 345, 421'

There are several problem here.
Python 3.x only use input(raw_input only work for 2.x) = assign variable(can not use in = in a if statement. == Compares if the objects are equal

To get a integer to return you can do it like this.

number_of_courses = int(input ('Please enter...'))

This will not store variabls,so only last input will count.
Look at dictionary as woooee suggsest.

for number_of_courses in range (0, number_of_courses):
       major = raw_input('Enter class type') #cmsc, math, etc..
       coursenum = input('Enter course number')

Edited 7 Years Ago by snippsat: n/a

Thank you so much for your help everybody. I am using sets for the courses and the course numbers.

How can I print the course numbers that are greater than the ones in the set?

For example, if user enters 201, it prints 202, 204, 213, etc... from the set. I tried the following:

if coursenum in courselistA:  #courselistA is the set of course numbers
       print ('courselistA >', coursenum)

but this didn't work. I've tried playing around with the parenthesis, and operations but still nothing. Any suggestions?

hey guys I really need help in this, this was due sunday night, I'm already 2 days late.

if coursenum in courselistA:  #courselistA is the set of course numbers
       #Convert courselistA into a list and use list comprehension
       print [x for x in list(courselistA) if x > coursenum]
This question has already been answered. Start a new discussion instead.