PCEP: Coding Exercises - Set 3

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

a) You need to create 3 functions b) The first function when invokved, will convert ft to m and inch to m and combine them: -> To convert ft to m is ft * 0.3045 -> To convert inch to m is inch * 0.0254 c) The second function will convert lb to kg -> To convert lb to kg is lb * 0.45459237 d) The third function will check the parameters of weight and height and will use a condition to make sure height is not less than 1.0 or height is not greater than 2.5 or weight is not greater than 200. If it is, it must return None e) If the above return is not None, then another return must be created to take the weight divided by the height to the exponent 2 to get the BMI f) Use the print function that calls the bmi and the parameters is weight that is equal to the function lb_to_kg with the parameter as 176, the second parameter starts with height and equal to the function ft_and_inch_to_m with parameters 5 and 7.

1. Create a function called ft_and_inch_to_m and create two parameters ft and inch and returns ft * 0.3045 + inch * 0.0254 2. Create a function called lb_to_kg with parameter lb and returns the weight * 0.45459237 3. Create a function bmi that has a parameters weight and height and uses a condition in which if height is less than 1.0 or height is greater than 2.5 or weight is greater than 200 then it returns None 4. Create a return that divides weight by height to the exponent 2 5. Create the print function that calls the bmi and the parameters is weight that is equal to the function lb_to_kg with the parameter as 176, the second parameter starts with height and equal to the function ft_and_inch_to_m with parameters 5 and 7. def ft_and_inch_to_m(ft, inch = 0.0): return ft * 0.3045 + inch * 0.0254 def lb_to_kg(lb): return lb * 0.45459237 def bmi(weight, height): if height < 1.0 or height > 2.5 or weight > 200: return None return weight / height ** 2 print(bmi(weight = lb_to_kg(176), height = ft_and_inch_to_m(5,7)))

Write a program that will convert the colors tuple to a dictionary. colors = (("green", "#008000"), ("blue", "#0000FF")) # Write your code here. print(colors_dictionary)

colors = (("green", "#008000"), ("blue", "#0000FF")) colors_dictionary = dict(colors) print(colors_dictionary)

Write a program that will "glue" the two dictionaries (d1 and d2) together and create a new one (d3) using a for loop with parameters d1 and d2 and the expression is the new dictionary name with the method update(i) d1 = {'Adam Smith': 'A', 'Judy Paxton': 'B+'} d2 = {'Mary Louis': 'A', 'Patrick White': 'C'} d3 = {}

d1 = {'Adam Smith': 'A', 'Judy Paxton': 'B+'} d2 = {'Mary Louis': 'A', 'Patrick White': 'C'} d3 = {} for item in (d1, d2): d3.update(item) print(d3)

Complete this code! def bmi(_____________, ____________): return _____________ /____________ ** 2 print(bmi(52.5, 1.65))

def bmi(weight, height): return weight / height ** 2 print(bmi(52.5, 1.65)) 19.283746556473833

Create a code that checks if the three numbers inputed can be a triangle. a) Create a function called is_a_triangle with 3 parameters a b c b) In order to be a triangle, it must return the following: conditions as True -> a combined with b is greater than c and -> b combined with c is greater than a and -> c combined with a is greather than b c) Create 3 float inputs that ask the user to input a number d) Create a condition function that invokes the function abc and prints yes if the trinagle is True or No if the triangle is False

def is_a_triangle(a,b,c): return a+b > c and b+c >a and c+a> b a = float(input('Enter the first side\'s length: ')) b = float(input('Enter the second side\'s length: ')) c = float(input('Enter the third side\'s length: ')) if is_a_triangle(a,b,c): print('Yes, it can be a triangle. ') else: print('No, it can\'t be a triagle. ')

Write a program that will convert the my_list list to a tuple. my_list = ["car", "Ford", "flower", "Tulip"] t = # Write your code here. print(t)

my_list = ["car", "Ford", "flower", "Tulip"] t = tuple(my_list) print(t)

my_tuple = (1, 10, 100) Use the list above to get the following outputs: 1) A new list that takes my_tuple and has new values: (1, 10, 100, 1000, 10000) 2) A new list that takes my_tuple and has the new values: (1, 10, 100, 1, 10, 100, 1, 10, 100) 3) Checks to see if there is a 1000 in the last list created

t1 = my_tuple + (1000, 10000) t2 = my_tuple * 3 print(1000 in lst3)


Set pelajaran terkait

Chapter 3: Ethnography and Anthro Practices

View Set

SOVEREIGNITY 1.2 + INTERDEPENDENCE 1.3

View Set

CLASS 2-Gas Exchange I-January 25th

View Set

Ch 46 - Hematologic or Neoplastic Disorder

View Set

Chapter 18: Intraoperative Nursing Management

View Set

Ch. 2 (Historical Perspectives) Questions

View Set

ATI HEALTH ASSESS: HEAD, NECK, NEUROLOGICAL

View Set