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!
Stackoverflow can be a minefield of useless or bad advice.
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.
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
your sanity checking:
if bad_course in courses:
courses.remove(bad_course)
else:
print("You're not taking", repr(bad_course))
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.