Source Code
session6.py
import random
import math
def main():
print("Menu System")
print("E1 - Example 1")
print("Q - Quit")
choice = input("Choice: ").upper()
if choice == "E1":
print("Example 1")
# example1 function call
example1()
elif choice == "E2":
print("Example 2")
# example2 function call
example2()
elif choice == "E3":
print("Example 3")
# example3 function call
example3()
elif choice == "E4":
# example4 function call
example4()
elif choice == "E5":
# example5 function call
example5()
elif choice == "E6":
# example6 function call
example6()
elif choice == "E7":
# example7 function call
example7()
elif choice == "E8":
# example8 function call
example8()
elif choice == "Q":
print("Quitting!")
else:
print("Invalid choice")
# example1 function definition
def example1():
print("Example 1")
# declare a 2D list
# access an element
# print matrix
# example2 function definition
def example2():
print("Example 2")
# declare a 2D list
# print matrix
# update an element
# print first row
# print first column
# example3 function definition
def example3():
print("Example 3")
# create an empty dictionary
# add items - key/value pairs
# print dictionary using a loop
# in operator
# example4 function definition
def example4():
print("Example 4")
# create a dictionary named languages
languages = {
"C": 1972,
"C++": 1983,
"Python": 1991,
"Lua": 1993,
"Java": 1995,
"JavaScript": 1995,
"Ruby": 1995,
"Go": 2009,
"Rust": 2010,
"Swift": 2014,
}
# print the number of items
# Remove specific key-value pair and return value
# Delete specific key
# print the average year
# example5 function definition
def example5():
print("Example 5")
# nested dictionary
# accessing a student's age
# modify a student's age
# add a new student
# delete a student
# iterate through a nested dictionary
# example6 function definition
def example6():
print("Example 6")
# create a tuple with one element
# print the first element
# example7 function definition
def example7():
print("Example 7")
# create a tuple
# loop through elements v1
# loop through elements v2
# example8 function definition
def example8():
print("Example 8")
# create a tuple
# Convert tuple to list
# Modify the list
# Convert back to tuple
# call the main function, do not delete!
main()
Last updated