# Need help with this String Function

I have this assignment that I need to complete and was just wondering if someone could give me some ideas on what commands to use.

My output needs to look like this, it needs to detect once you have 5 classes or more and then prompt you to remove them accordingly. I would like to know which command I would need to execute in order to have this statement be true as well as how to make an enumerated list like the one shown. I have already tried with an enumerate function I found on stack overflow, but there is very little help related to this type of situation.

What courses would you like to take? Sociology ,english,CompSci, psychology
You are currently taking these courses:
1: Math
2: Physics
3: Science
4: Sociology
5: English
6: Compsci
7: Psychology

What courses would you like to drop? compsci
You are currently taking these courses:
1: Math
2: Physics
3: Science
4: Sociology
5: English
6: Psychology

To recap, what would I need to do in order to establish that once there are 5 courses, I must prompt the drop statement above, and what would I need to do in order to get a numbered list like this with each corresponding input.

Whoever can help me with this, you’re a lifesaver!

Let’s think about what you’re asking: you are taking some courses. You
can’t take the same course twice at the same time. (Let us ignore that I
once took a course and tutored part of it:-)

So you want a collection which can only have one member of a particular
type. That would be a set, which in Python is very much like a concrete
finite sized set in mathematics.

So:

courses = {'Sociology','english','CompSci', 'psychology'}

Like other containers, you can take the length of a set: len(courses).
That tells you how many courses you are taking.

Sets are iterable, so you can print them out or use them in a for-loop:

for course in courses:
print(course)

Note that strings are compared exactly, so ‘compsci’ is not ‘CompSci’.
You might like to keep only “normalised” names in your set, for example
by lowercasing them. Or you might like to look names up as part of

else:

and expect the user to type carefully. The latter approach is easier to
implement and probably what you should do for your first attempt.

Come back with code and its unwanted behaviour if you get stuck.

Cheers,
Cameron Simpson cs@cskk.id.au

Hi ! - You would only need to drop an assignment and there are two possibilities :

a) you write a class like :

class courses:
a = "Math"
b = "Physics"
c = "Science"
d = "Sociology"
e = "English"
f = "Compsci"
g = "Psychology"

You can get output then with :

>>> print(a)
Math

You then need only later in listing to drop an assignment with command :

del a

or you can write in assignment in class later this :

class courses:
a = None

After dropping the assignments with del like above you get with :

print(a)

then this output :

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined

or with assignment “None” from before - you get then this
as example b) :

>>> print(a)
None

A more appropriate answer would be to solve this
with so-called “inheritance of variables in classes”:

This is explained here :