 # Gimme5 - Functions

Jan 15th, 2022 (edited)
112
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # Gimme5 functions by Colin
2. """
3. 1.  Create a function that passes a number as a parameter and returns 30 times that number
4.
5. 2.  Create a function that takes a year of birth as a parameter and returns their age this year
6.
7. 3.  Create a function that takes the radius as a parameter of a circle and returns its area
8.
9. 4.  Create a function that takes width and length as parameters and returns the area
10.
11. 5.  Create a function that takes a time in minutes and returns hours and mins
12. """
13.
14. #1
15. #triple a number
16.
17. def triple(anumb):
18.     answer = anumb * 3
20.
21. #call and print a function
22.
23. numb = int(input("enter a number >>> "))
24.
25. print(triple(numb))
26.
27. #test
28. #input 20 should give 60
29.
30.
31. #2
32. #calc age inputting year
33.
34. def calcage(year):
35.     age = 2022 - year # 2022 is hard coded needs updating in 2023
36.     return age
37.
38. numb = int(input("enter year of birth >>> "))
39.
40. print("This year you will be", calcage(numb))
41.
42. # test
43. # 1958 give 64 (in 2022)
44.
45.
46. #3
47. #area of a circle
48.
49. PI = 3.142
50.
52.     area = PI * (radius **2 )
53.     return area
54.
56.
58.
59. # test https://www.omnicalculator.com/math/area-of-a-circle
60.
61. # radius 5.26 => 86.92 (rounding may impact)
62.
63.
64. #4
65. #area of a rectangle, input width and length - 2 x parameters
66.
67. def area_of_rectangle(width, height):
68.     area = width * height
69.     return area
70.
71. width_input = float(input("Enter width >> "))
72. height_input = float(input("Enter height >> "))
73.
74. print("The area of a rectangle with", height_input, "and", width_input, "is", round(area_of_rectangle(width_input, height_input),2))
75.
76. #  test data
77. # 3.6 * 3.9 = 14.04
78.
79.
80. #5 convert mins to hrs and mins
81.
82. def mins2hrsmins(minutes):
83.     hrspart = minutes //60
84.     minspart = minutes % 60
85.     return str(hrspart)+ ":"+ str(minspart)
86.
87. mins_input = int(input("Enter minutes to convert to hrs : mins >> "))
88.
89. print(mins_input, "is",mins2hrsmins(mins_input))
90.
91. #test data
92. # 999 mins = 16hrs and 39 mins
RAW Paste Data Copied