😎
CS1.dev
  • Welcome to Computer Science 1
  • Unit 2
    • Activity 2.1
    • Activity 2.2
    • Activity 2.3
    • Activity 2.4
    • Activity 2.5
    • Activity 2.6
    • Activity 2.7
    • Activity 2.9
    • Activity 2.10
    • Project 2
    • Activity 2.8
    • Activity 2.11
    • Activity 2.12
    • Activity 2.13
    • Activity 2.14
    • Activity 2.15
    • Activity 2.16
    • Activity 2.17
    • Activity 2.18
    • Activity 2.19
    • Project 3
    • Activity 2.20
    • Activity 2.21
    • Activity 2.22
    • Activity 2.23
    • Activity 2.24
    • Project 4
    • Activity 2.25
    • Activity 2.26
    • Activity 2.27
    • Activity 2.28
    • Project 5
    • Activity 2.29
    • Activity 2.30
    • Activity 2.31
    • Activity 2.32
    • Activity 2.33
    • Activity 2.34
    • Activity 2.35
    • Activity 2.36
  • Unit 3
    • Activity 3.1
    • Activity 3.2
    • Activity 3.3
    • Activity 3.4
    • Activity 3.5
    • Activity 3.6
    • Activity 3.7
    • Activity 3.8
    • Activity 3.9
    • Activity 3.10
    • Activity 3.11
    • Project 6
    • Activity 3.12
  • Activity 3.13
  • Activity 3.14
  • Activity 3.15
  • Activity 3.16
  • Project 7
  • Activity 3.17
  • Activity 3.18
  • Activity 3.19
  • Project 8
  • Linux
    • bash
    • cat
    • cd
    • chmod
    • df
    • echo
    • find
    • grep
    • less
    • ls
    • mkdir
    • more
    • pwd
    • tar
    • touch
    • unzip
    • zip
Powered by GitBook
On this page
  • Source Code
  • playlist.py
  1. Unit 2

Activity 2.22

Source Code

import math
import random

def main():
    done = False
    while not done:
        print("Menu System")
        print("E1 - Example 1")
        print("Q - Quit")
        choice = input("Choice: ").upper()
        if choice == "E1":
            # example1 function acll
            example1()
        elif choice == "Q":
            print("Quitting!")
            done = True
        else:
            print("Invalid choice")

# example1 function definition
def example1():
    print("Example 1")
    # create a list of 10 movies
    popular_movies = [
        "Barbie",
        "Oppenheimer",
        "Spider-Man: No Way Home",
        "Top Gun: Maverick",
        "Avatar: The Way of Water",
        "Guardians of the Galaxy Vol. 3",
        "The Super Mario Bros. Movie",
        "Joker",
        "Everything Everywhere All at Once",
        "The Batman"
    ]
    # print the list


    # print a random movie


    # in operator


# call the main function, do not delete!
main()

playlist.py

import math
import random

def main():
    # add initial songs
    playlist = []

    done = False
    while not done:
        print("Playlist Manager")
        print("1. Add a song")
        print("2. Remove a song")
        print("3. View playlist")
        print("4. View playlist with index positions")
        print("5. Select a random song")
        print("6. Sort playlist")
        print("7. Reorder playlist")
        print("8. Clear playlist")
        print("9. Shuffle Playlist")
        print("10. Exit")
        choice = int(input("Choose an option (1-10): "))
        if choice == 1:
            print("Add a song")


        elif choice == 2:
            print("Remove a song")


        elif choice == 3:
            print("My current playlist")


        elif choice == 4:
            print("My current playlist with index positions")


        elif choice == 5:
            print("Here's a random song!")


        elif choice == 6:
            print("Sort my playlist alphabetically")

        
        elif choice == 7:
            print("Reorder playlist")
            

        elif choice == 8:
            playlist.clear()
            print("Playlist cleared.")
            
        elif choice == 9:
            print("Shuffle Playlist")


        elif choice == 10:
            print("Goodbye!")
            done = True

        else:
            print("Invalid choice. Please try again.")

# call the main function
main()
PreviousActivity 2.21NextActivity 2.23

Last updated 4 months ago