Skip to content
Snippets Groups Projects
Commit 5f6b23cd authored by Daniel Moix's avatar Daniel Moix
Browse files

Adding CS 172 Lecture 1 files

parent 95f94991
Branches
No related tags found
No related merge requests found
import notModule
print(notModule.larger(11, 22))
# from notModule import sum
# print(sum(11, 22))
# from notModule import sum, larger
# print(sum(11, 22))
\ No newline at end of file
def sum(num1, num2):
return num1+num2
def larger(num1, num2):
if num1 > num2:
return num1
else:
return num2
\ No newline at end of file
def sum(num1, num2):
return num1+num2
def larger(num1, num2):
if num1 > num2:
return num1
else:
return num2
\ No newline at end of file
# Program: Simulate a Pringle Can
class can:
#Constructor
def __init__(self, flavor):
self.__isOpen = False
self.__numChips = 50
self.__flavor = flavor
def eat(self):
if self.__isOpen and self.__numChips > 0:
self.__numChips -= 1
def open(self):
self.__isOpen = True
def close(self):
self.__isOpen = False
def getChips(self):
return self.__numChips
def isEmpty(self):
return self.__numChips == 0
def __str__(self):
return "A " + self.__flavor +" Pringle Can containing " \
+ str(self.__numChips) + " chips."
# Attributes: number of chips, flavor, open or not
myCan = can("BBQ") #Create a new, full, closed can
myCan.open()
while not myCan.isEmpty():
myCan.eat()
print("Mmm")
myCan.close()
print(myCan.getChips())
print(myCan)
print("Hello")
print("Goodbye")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment