Question

In: Computer Science

for Python 3 Write a python program that Creates a list that has these values in...

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()
  

Solutions

Expert Solution

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()


Related Solutions

In python write a program that first creates a list with the integers 0 through 9...
In python write a program that first creates a list with the integers 0 through 9 and then traverses that list RECURSIVELY (no for/while loops allowed) and prints out the integers on the list. NOTE: creating the list does not have to be done recursively.
Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6)....
Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6). Print the first 3 elements from the list using slice expression. a. Extend this program in a manner that the elements in the list are changed to (6, 9, 12, 15, 18) that means each element is times 3 of the previous value. b. Extend your program to display the min and max value in the list.
Write a program in python such that There exists a list of emails List Ls =...
Write a program in python such that There exists a list of emails List Ls = ['[email protected]','[email protected]','[email protected]','[email protected]',[email protected]'] Count the number of emails IDS which ends in "ac.in" Write proper program with proper function accepting the argument list of emails and function should print the number of email IDs and also the email IDS ending with ac.in output 2 [email protected] [email protected] ================================= i am trying like this but getting confused len [True for x in Ls if x.endswith('.ac.in')] please write complete...
Please write in Python code please Write a program that creates a dictionary containing course numbers...
Please write in Python code please Write a program that creates a dictionary containing course numbers and the room numbers of the rooms where the courses meet. The dictionary should have the following key-value pairs: Course Number (key) Room Number (value) CS101 3004 CS102 4501 CS103 6755 NT110 1244 CM241 1411 The program should also create a dictionary containing course numbers and the names of the instructors that teach each course. The dictionary should have the following key-value pairs: Course...
Exercise #3 python Write a program that could evaluate the relationship between two values. User is...
Exercise #3 python Write a program that could evaluate the relationship between two values. User is to key in the two values, and it will be stored in variable, num1 and num2. The program will do a comparison between the two values. If num1 is greater than num2, a message will be display on screen to indicate that num1 is greater than num2. The program will also display appropriate messages when num2 is greater than num1; and num1 is equal...
Write a C program that creates and prints out a linked list of strings. • Define...
Write a C program that creates and prints out a linked list of strings. • Define your link structure so that every node can store a string of up to 255 characters. • Implement the function insert_dictionary_order that receives a word (of type char*) and inserts is into the right position. • Implement the print_list function that prints the list. • In the main function, prompt the user to enter strings (strings are separated by white-spaces, such as space character,...
Write a multithreaded program that calculates various statistical values for a list of numbers. This program...
Write a multithreaded program that calculates various statistical values for a list of numbers. This program will be passed a series of numbers on the command line and will then create three separate worker threads. One thread will determine the average of the numbers, the second will determine the maximum value, and the third will determine the minimum value. For example, suppose your program is passed the integers 90 81 78 95 79 72 85 The program will report The...
Write a Python program that performs the following list operations. Part A Define a list called...
Write a Python program that performs the following list operations. Part A Define a list called numList with elements. 84, 94, 27, 74, 19, 90, 16, 21, 56, 50, 77, 59, 41, 63, 18, 26, 80, 74, 57, 30, 40, 93, 70, 28, 14, 11, 43,65, 91, 83, 22, 53, 74, 44, 73, 55, 47, 74, 81 Display the followings: All the numbers in numList The number of elements in numList The smallest number in numList The largest number in...
#Write a program in Python that given a list of positive integers, return another list where...
#Write a program in Python that given a list of positive integers, return another list where each element corresponds to the sum of the digits of the elements o#f the given list. #Example: # input # alist=[124, 5, 914, 21, 3421] # output # sum=[7, 5, 14, 3, 18]
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,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT