Activity 2.1
Source Code
import random
def main():
done = False
while not done:
print("Menu System")
print("E1 - Example 1")
print("P1 - Problem 1")
print("P2 - Problem 2")
print("P3 - Problem 3")
print("P4 - Problem 4")
print("Q - Quit")
choice = input("Choice: ")
if choice == "E1":
example1()
elif choice == "E2":
example2()
elif choice == "P1":
print("Problem 1")
elif choice == "P2":
print("Problem 2")
elif choice == "P3":
print("Problem 3")
elif choice == "P4":
print("Problem 4")
elif choice == "Q":
print("Quitting!")
done = True
else:
print("Invalid choice")
# example1 function definition
def example1():
print("Example 1")
# create a list of the first 10 numbers
numbers = []
for x in range(1, 11):
numbers.append(x)
# print the index and values
print("Index\tValue")
for x in range(len(numbers)):
print(str(x) + "\t" + str(numbers[x]))
# index of 5
# example2 function definition
def example2():
print("Example 2")
# create a list
numbers = []
for x in range(5):
numbers.append(1)
for x in range(4):
numbers.append(2)
numbers.append(3)
# print the index and values
print("Index\tValue")
for x in range(len(numbers)):
print(str(x) + "\t" + str(numbers[x]))
# count 1's, 2's, 3's
# sort the list in ascending order
# sort the list in desending order
# problem1 function definition
# problem2 function definition
# problem3 function definition
# problem4 function definition
# call the main function, do not delete!
main()
Last updated