Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Gimme5 functions by Colin
- """
- 1. Create a function that passes a number as a parameter and returns 30 times that number
- 2. Create a function that takes a year of birth as a parameter and returns their age this year
- 3. Create a function that takes the radius as a parameter of a circle and returns its area
- 4. Create a function that takes width and length as parameters and returns the area
- 5. Create a function that takes a time in minutes and returns hours and mins
- """
- #1
- #triple a number
- def triple(anumb):
- answer = anumb * 3
- return answer
- #call and print a function
- numb = int(input("enter a number >>> "))
- print(triple(numb))
- #test
- #input 20 should give 60
- #2
- #calc age inputting year
- def calcage(year):
- age = 2022 - year # 2022 is hard coded needs updating in 2023
- return age
- numb = int(input("enter year of birth >>> "))
- print("This year you will be", calcage(numb))
- # test
- # 1958 give 64 (in 2022)
- #3
- #area of a circle
- PI = 3.142
- def area_of_circle(radius):
- area = PI * (radius **2 )
- return area
- rad = float (input("Enter radius >> "))
- print("The area of a circle with radius", rad ,"is", round(area_of_circle(rad),2))
- # test https://www.omnicalculator.com/math/area-of-a-circle
- # radius 5.26 => 86.92 (rounding may impact)
- #4
- #area of a rectangle, input width and length - 2 x parameters
- def area_of_rectangle(width, height):
- area = width * height
- return area
- width_input = float(input("Enter width >> "))
- height_input = float(input("Enter height >> "))
- print("The area of a rectangle with", height_input, "and", width_input, "is", round(area_of_rectangle(width_input, height_input),2))
- # test data
- # 3.6 * 3.9 = 14.04
- #5 convert mins to hrs and mins
- def mins2hrsmins(minutes):
- hrspart = minutes //60
- minspart = minutes % 60
- return str(hrspart)+ ":"+ str(minspart)
- mins_input = int(input("Enter minutes to convert to hrs : mins >> "))
- print(mins_input, "is",mins2hrsmins(mins_input))
- #test data
- # 999 mins = 16hrs and 39 mins
Add Comment
Please, Sign In to add comment