$30
I want to do a survey to determine the majors of students taking CS160. To do this, write a
program that asks for a student’s major. For this program the only majors I’m concerned with
are Computer Science, Data Science, and Cyber Security. To simplify data entry, we will use the
terms “cs” for Computer Science, “data” for Data Science, and “cyber” for Cyber Security.
Anything other than those three majors will be considers as “Other Major.”
Continue to ask for majors until the user enters a major of “done”. Make sure that this entry is
not counted towards the “Other Majors” category. Total up all the entries for each of the
specified major, along with the total for other Majors.
For only the CS majors we want to ask about their minor. The only minors we are interested in
tracking are Data Science, Cyber Security, and Mathematics. Again, to simplify the input, we will
accept “data” for the Data Science Minor, “cyber” for the Cyber Security minor, and “math” for
the Mathematics minor. If a student is a Computer Science major ask for their minor
immediately, before asking for the next student’s major.
Specifics:
• All strings entered will be lower case (“cs”, “data”, “cyber”, “math”). While we will not
enter test data with mixed cases, entering “DATA” for the major or minor would place
that entry in the other category.
• When comparing strings you may use .lower() to convert a string to an upper or lower
case string. This will be a topic for future classes. For now, to ensure a string contains
only lower case letters assign the variable back to itself as follows:
stringVariable = stringVariable.lower()
• Only ask for the minor for Computer Science majors
• “Other Majors” is not a major, it is just a means of referring to anything other than the
specified majors.
• Your program should include a comment section with your name, lab time, lecture time,
and email address.Output
After all of the data has been entered print out the following information:
• The number of students entering their major
• The number and percentage of students from the class for each of the three specified
major, and for other (anything other than the three specified majors). Note that it is
possible for the summation of the four percentages to not add up to 100 due to round
off error. If this happens, the summation, which is not required to be printed, should be
99.99. The majors should be left justified, with the number of students and the
percentages right justified. The percentage should have two places after the decimal
point.
• The number and percentage of each minor. As with the table created for the majors, the
name of the minors should be left justified, with the number of students and the
percentages right justified. The percentage should have two places after the decimal
point.
For example, if the following data was entered this is what the program might display. Note
that this output is typed, not actual output from running the program, so there may be typos.
Enter major: cs
Enter minor: data
Enter major: data
Enter major: cyber
Enter major: econ
Enter major: none
Enter major: done
This could be the output from the above data:
Total number of students 5
Majors of students in CS160
Computer Science 1 20.00
Data Science 1 20.00
Cyber Security 1 20.00
Other Majors 2 40.00
Minors for Computer Science Majors in CS160
Data Science 1 100.00
Cyber Security 0 0.00
Mathematics 0 0.00
Other Minors 0 0.00