5.28. Functions and Conditionals Write Code Questions¶
Write a function called
cropped_photothat takes theheightandwidthof a photo. If theheightandwidthare equal, then the function returns"Cropped Photo". Otherwise, it returns"The photo needs to be cropped."Assumeheightandwidthare positive. For example,cropped_photo(23.2, 23.2)should return"Cropped Photo".Write a function called
cropped_photothat takes theheightandwidthof a photo. If theheightandwidthare equal, then the function returns"Cropped Photo". Otherwise, it returns"The photo needs to be cropped."Assumeheightandwidthare positive. For example,cropped_photo(23.2, 23.2)should return"Cropped Photo".-
Write a function called
bonusthat takes two parameters,yearsandquality. Ifyearsis more than 5, then the person gets a bonus. The person also gets a bonus if theirqualityof work was more than 90. They can also get a bonus if they worked for at least 3yearsand hadqualitymore than 80. If the person is eligible for a bonus, return"Eligible for Bonus". Otherwise, return"Ineligible for Bonus". For example,bonus(3, 81)should return"Eligible for Bonus". Write a function called
move_elevatorthat takes two parameters,current_floorandnext_floor. If the elevator moves to a floor above, then it should return"Up". Otherwise, it should return"Down". Also, ifnext_flooris the same ascurrent_floor, it should return 0. Assume there are no 0 or negative floors. For example,move_elevator(5, 8)should return"Up".Write a function called
move_elevatorthat takes two parameters,current_floorandnext_floor. If the elevator moves to a floor above, then it should return"Up". Otherwise, it should return"Down". Also, ifnext_flooris the same ascurrent_floor, it should return 0. Assume there are no 0 or negative floors. For example,move_elevator(5, 8)should return"Up".-
Write a function called
lunch_breakthat takes a parameterclass_standingand determines how long a lunch break will be based on the student’s class standing. If a person is a ‘Freshman’, return40. If a person is a ‘Sophomore’, return30. If a person is a ‘Junior’, return20. If a person is a ‘Senior’, return15. If a person is none of these, return0. For example,lunch_break('Alumni')should return0. Write a function called
pay_rentthat takes in one parameter,units. Ifunitsis less than 200, return"$100". Ifunitsis less than 500 and greater than or equal to 200, return"$200". Otherwise, return"$300". For example,pay_rent(175)should return"$100".Write a function called
pay_rentthat takes in one parameter,units. Ifunitsis less than 200, return"$100". Ifunitsis less than 500 and greater than or equal to 200, return"$200". Otherwise, return"$300". For example,pay_rent(175)should return"$100".-
Write a function called
play_weatherthat takes the stringweatheras a parameter and returns if one should play or not. If theweatheris ‘sunny’ or ‘cloudy’, then the function should return"The person should play". If theweatheris ‘rainy’, ‘windy’ or ‘snowy’, then the function should return"The person should not play". If theweatheris none of these, the function should return"It is not safe to go outside". For example,play_weather('sunny')should return"The person should play".