In: Computer Science
for Python 3
Write a python program that Creates a list that has these values in this order, 'Python', 'JavaScript', and 'PHP' 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. Define a guessNext function that selects a random element from the list and returns it to the call of the function. 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. 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. Once the loop is exited, call the displayMyClasses to display the current contents of the list. Now call the guessNext function and receive the random class value returned. Display "The next class you should teach is: (the random class)" Below is a example of how the program should run the program should run in a similar manner no matter what names and age are entered. 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
here is what i have so far and i am stuck....
mylist = ["Python", "JavaScript", "PHP"]
def main():
print("Assignment 5\n")
def displayMyClasses():
print("List of Classes I Teach: ")
print(mylist)
mylist.sort()
for item in mylist:
print(item)
def guessNext():
if __name__ == "__main__":
main()
import random classes=['Python','JavaScript','PHP'] def displayMyClasses(): print("List of Classes I Teach: \n") j=1 for i in sorted(classes): print('{:d}. {:s}'.format(j,i)) j=j+1 def guessNext(): return classes[random.randrange(0,len(classes))] def main(): print("Assignment 5\n") displayMyClasses() ip=input('\nDo you need to Add or Remove a class? (A/R) ') while len(ip)>0: if ip=='A': addClass=input('Enter the name of the class you wish to add: ') classes.append(addClass) elif ip=='R': removeClass=input('Enter the name of the class you wish to remove: ') classes.remove(removeClass) else: print("You must choose an 'A' to Add or an 'R' to Remove a class") ip = input('\nDo you need to Add or Remove a class? (A/R) ') displayMyClasses() rClass=guessNext() print('The next class you should teach is:',rClass) main()