Challenges 8
Challenges 8
8a). Complete the 3 sub programs below:
Low: Create a procedure called RepeatName which takes 2 parameters Name and Repeat. It takes in a name then prints it out the number of times in the parameter Repeat.
Example:
RepeatName("Mary",5)
Mary
Mary
Mary
Mary
Mary
Med: Create a function which calculates the perimeter of a rectangle. 2xWidth + 2xHeight.
Example:
a=RectanglePerimiter(10,20)
print(a)
60
High: Create a function that returns that last 3 letters of a string. If the string is less than 3 characters then add Xs at the end to fill gaps.
Example:
a=LastLetters("Yi")
print(a)
YiX
a=LastLetters("Campbell")
print(a)
ell
8b). Create the following functions:
Low: Write a Python function called TotalMinutes which takes two parameters hours and minutes. It then returns the total minutes.
Example:
h=3
m=20
time=TotalMinutes(h,m)
print(time)
--------------------
200
Med: Write a Python function called MaxNumber which takes as single parameter, an array/list of numbers, then returns the maximum (largest) number found. So below the largest number in the list is 13.
Example:
l=[3,1,9,6,7,13,2]
m=MaxNumber(l)
print(m)
--------------------
13
Med: P-Cubed make special secure boxes. Employees earn days of holiday based on how long they have worked at P-Cubed.
• For the first two years, employees get 10 days of holiday each year.
• In subsequent years, employees get an additional 0.5 days of holiday for each year worked.
Create a function, HolidayDays, that has 1 parameter, years worked, and returns the holiday allowance for the employee.