In: Computer Science
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
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