Question

In: Computer Science

Overview: You will write a python program that will work with lists and their methods allowing...

Overview: You will write a python program that will work with lists and their methods allowing you to manipulate the data in the list. Additionally you will get to work with randomization.

Instructions:

Please carefully read the Instructions and Grading Criteria.

Write a python program that will use looping constructs as noted in the assignment requirements.

Name your program yourlastname_asgn5.py

Assignment Requirements

IMPORTANT: Follow the instructions below explicitly.
Your program must be structured as I describe below.


Write a Python program that ...

1. Creates a list that has these values in this order, 'Python', 'JavaScript', and 'PHP'


2. Define a displayMyClasses function that sorts the list and then displays each item on the list, one per line, in sorted order. Also, number the displayed list as shown in the "Running a Sample Program" shown below.

3. Define a guessNext function that selects a random element from the list and returns it to the call of the function.

4. When the program begins, the main function should display the "Assignment 5" title as the first line and then call the displayMyClasses function to display the current contents of the list.

5. Next, prompt the user to enter an "A" to add a new class to the list or enter an "R" to remove a class from the list.

If the user enters a blank, exit the loop.

If the user enters an "A", then prompt them to enter the name of the class they want to add to the end of the list and, after they answer, add the class to the end of the list.

If the user enters an "R", then prompt them to enter the name of the class they want to remove from the list and, after they answer, remove the class from the list.

If the user has not entered an "A" or and "R" display a message that says "You must choose an 'A' to Add or an 'R' to Remove a class" and start the code back at the top of this #5 step so that they get re-prompted for the correct information.

6. Once the loop is exited, call the displayMyClasses to display the current contents of the list.

7. Now call the guessNext function and receive the random class value returned.

Display "The next class you should teach is: (the random class)"

8. Display "END OF ASSIGNMENT 5"

Running a Sample Program

Below is a example of how your program might run if you used the same answers to the prompts I used below. Your program should run in a similar manner... no matter what names (data) are entered.

NOTE: The data I entered appear in maroon bold

Sample Run...


Assignment 5

List of Classes I Teach:

1. JavaScript
2. PHP
3. Python

Do you need to Add or Remove a class? (A/R) A

Enter the name of the class you wish to add: HTML

Do you need to Add or Remove a class? (A/R) R

Enter the name of the class you wish to remove: PHP

Do you need to Add or Remove a class? (A/R) A

Enter the name of the class you wish to add: PHP with MySQL

Do you need to Add or Remove a class? (A/R) d

You must choose an 'A' to Add or an 'R' to Remove a class

Do you need to Add or Remove a class? (A/R)

List of Classes I Teach:
1. HTML
2. JavaScript
3. PHP with MySQL
4. Python

The next class you should teach is: JavaScript

END OF ASSIGNMENT 5

Solutions

Expert Solution

here i am uploading the code for your assignment. hope this will help you.

****************************kumarsah_asgn5.py***************************

import random

class_list = ['Python', 'JavaScript', "PHP"]


def displayMyClasses():
    class_list.sort()
    print("List of Classes I Teach:")
    for i in range(0, len(class_list)):
        print(f'{i + 1}. {class_list[i]}')


def guessNext():
    random_class = random.choice(class_list)
    return random_class


def option():
    flag = True
    while flag:
        choice = input("Do you need to Add or Remove class?(A/R) ")
        if choice == 'A':
            class_name = input("Enter the name of the class you wish to add: ")
            class_list.append(class_name)
        elif choice == 'R':
            class_remove = input("Enter the name of class you wish to remove: ")
            class_list.remove(class_remove)
        elif choice == '':
            flag = False
        else:
            print("You must choose 'A' to Add or an 'R' to Remove a class")

    displayMyClasses()
    print(f'The next class you should teach is: {guessNext()}')
    print("END OF ASSIGNMENT 5")


if __name__ == '__main__':
    print("Assignment 5")
    displayMyClasses()
    option() 

************************end of code*********************

here i am uploading the snippet


Related Solutions

For this lab, you will work with two-dimensional lists in Python. Do the following: Write a...
For this lab, you will work with two-dimensional lists in Python. Do the following: Write a function that returns the sum of all the elements in a specified column in a matrix using the following header: def sumColumn(matrix, columnIndex) Write a function display() that displays the elements in a matrix row by row, where the values in each row are displayed on a separate line. Use a single space to separate different values. Sample output from this function when it...
Please include comments on what you are doing.   Using linked lists, write a Python program that...
Please include comments on what you are doing.   Using linked lists, write a Python program that performs the following tasks: store the records for each college found in the input file - colleges.csv - into a linked list. (File includes name and state data fields) allow the user to search the linked list for a college’s name; display a message indicating whether or not the college’s name was in the database allow the user to enter a state's name and...
PYTHON Computer Science Objectives Work with lists Work with functions Work with files Assignment Write each...
PYTHON Computer Science Objectives Work with lists Work with functions Work with files Assignment Write each of the following functions. The function header must be implemented exactly as specified. Write a main function that tests each of your functions. Specifics In the main function ask for a filename and fill a list with the values from the file. Each file should have one numeric value per line. This has been done numerous times in class. You can create the data...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
Use PYTHON --Nested Lists and DateTime Module. Write a program that does the following: Reads information...
Use PYTHON --Nested Lists and DateTime Module. Write a program that does the following: Reads information from a text file into a list of sublists. Be sure to ask the user to enter the file name and end the program if the file doesn’t exist. Text file format will be as shown, where each item is separated by a comma and a space: ID, firstName, lastName, birthDate, hireDate, salary Store the information into a list of sublists called empRoster. EmpRoster...
Python This week you will write a program in Python that mimics an online shopping cart...
Python This week you will write a program in Python that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers...
Overview In this assignment, you will write a program to track monthly sales data for a...
Overview In this assignment, you will write a program to track monthly sales data for a small company. Input Input for this program will come from two different disk files. Your program will read from these files by explicitly opening them. The seller file (sellers.txt) consists of an unknown number of records, each representing one sale. Records consist of a last name, a first name, a seller ID, and a sales total. So, for example, the first few records in...
Given two lists, write python code to print “True” if the two lists have at least...
Given two lists, write python code to print “True” if the two lists have at least one common element. For example, x = [1,2,3], y=[3,4,5], then the program should print “True” since there is a common element 3.
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT