Started Rectangle Project

This commit is contained in:
cmitchell2301 2025-12-14 18:34:36 -05:00
commit 26e1253c0d
39 changed files with 544 additions and 0 deletions

View file

@ -0,0 +1,45 @@
# Simple function examples
#No input parameters
def myFunction1():
print("You are in myFunction1")
# Two input patrameters
def myFunction2(x,y):
print("You are in myFunction2")
print("x = ",x)
print("y = ",y)
return(x + y)
# Two input parameters with predefined valiues.
# Provide one or no parameters. If not specified the default values will be used.
def myFunction3(x = 2,y = 3):
print("You are in myFunction3")
print("x = ",x)
print("y = ",y)
return(x + y)
# ======================== Main Program =============================
myFunction1()
retValue = myFunction2(3,4)
print(retValue)
retValue = myFunction2(5,6)
print(retValue)
# This generates an error
#retValue = myFunction2(4)
#print(retValue)
retValue = myFunction3(3,4)
print(retValue)
retValue = myFunction3(5)
print(retValue)
# This does not generate an error
retValue = myFunction3()
print(retValue)

View file

@ -0,0 +1,16 @@
# list as an input parameter
def myFunction4(listParameter):
for listItem in listParameter:
print("\tlistParameter item: ",listItem)
myList = listParameter
myList.sort()
return( myList ) # Return a list
# ======================== Main Program =============================
fruits = ['Mango','Banana','Cherry', 'Apples']
print("\n Starting list: ",fruits)
print("\n")
sortedFruits = myFunction4(fruits)
print("\n Returned list: ",sortedFruits)

View file

@ -0,0 +1,25 @@
def updatePerson(personDict):
myPerson = personDict
emailAddress = input("Enter your email address: ")
phoneNumber = input("Enter your phone number: ")
myPerson['email'] = emailAddress
myPerson['phone'] = phoneNumber
return myPerson
import pprint
person = {'Name': 'Zara', 'Age': 7, 'Class': 'First','Color':'Green'}
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(person)
print("\n")
for key in person.keys():
print(f" {key:12} {person[key]} ")
person2 = updatePerson(person)
for key in person2.keys():
print(f" {key:12} {person2[key]} ")

View file

@ -0,0 +1,40 @@
# Simple function examples
def rectanglePerimeter(rLength,rWidth):
'''
rLength: length of the rectangle.
rWidth: width of the rectangle.
Returns the perimeter of the rectangle.'''
perimeter = 2 * (rLength + rWidth)
return(perimeter)
def rectangleArea(rLength,rWidth):
area = rLength * rWidth
return(area)
def squarePerimeter(rLength):
perimeter = rectanglePerimeter(rLength,rLength)
return(perimeter)
def squareArea(rLength):
area = rectangleArea(rLength,rLength)
return(area)
# ======================== Main Program =============================
length = 2.
width = 3.
retValue = rectanglePerimeter(length,width)
print(retValue)
retValue = rectangleArea(length,width)
print(retValue)
retValue = squarePerimeter(length)
print(retValue)
retValue = squareArea(length)
print(retValue)