Activity 3.16
Source Code
import math
import random
import student
def main():
print("Main Menu")
print("E1 - Example 1")
print("Q - Quit")
done = False
while not done:
choice = input("Choice: ").upper()
if choice == "Q":
print("Quit!")
done = True
elif choice == "E1":
example1()
elif choice == "E2":
example2()
elif choice == "P1":
pass
elif choice == "P2":
pass
elif choice == "P3":
pass
elif choice == "P4":
pass
elif choice == "P5":
pass
elif choice == "P6":
pass
elif choice == "P7":
pass
elif choice == "P8":
pass
elif choice == "P9":
pass
elif choice == "P10":
pass
elif choice == "Q":
print("Quitting!")
done = True
else:
print("Invalid Choice")
# define Example 1 Function
def example1():
print("Example 1")
# create object
winsel = student.Student("Winsel", 100)
winsel.add_food("Cheese Burger", 9.99)
winsel.add_food("Fries", 5.99)
winsel.add_food("Coke", 1.99)
print(winsel)
# define Example 1 Function
def example2():
print("Example 2")
# create object
# problem1 function definition
# problem2 function definition
# problem3 function definition
# problem4 function definition
# problem5 function definition
# problem6 function definition
# problem7 function definition
# problem8 function definition
# problem9 function definition
# problem10 function definition
# call to main function, do not delete!
main()
student.py
# header
class Student:
# constructor
# methods
# __str__ method
def __str__(self):
output = "Student: " + self.name + "\n"
output += "Money: $" + str(self.money) + "\n"
output += "Food(s) Ordered:\n"
for dish, price in self.food.items():
output += dish + " $" + str(price) + "\n"
return output
Last updated