Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is for python 3. I only need answers for questions 4-8. Thank you! Instructions: 1) (5 points) Write a function, multiples, that takes two

This is for python 3. I only need answers for questions 4-8. Thank you!
image text in transcribed
image text in transcribed
image text in transcribed
Instructions: 1) (5 points) Write a function, multiples, that takes two parameters, n1 and n2. The function should , nl "n2. then print results of ni . 0, 1" 1, n1 : 2 Function call Output (printed) multiplea(S7 10 1s 20 25 30 35 multiplea(3,2 2) (5 points) Write a function, double flip_coins, that flips two coins until they are either both heads or both tails, then returns the number of flips completed. Use the random.randint (begin, end) function to complete this exercise. Note that using random means that you'll get different output each time! Note: if the return value of this function is 1* that means that both coins were flipped once. If the return value is "10" that means that both coins were flipped 10 times (for 20 individual flips). Function call double-flip-coin#0 double flip coins double-flip-coin#0 Return value 3) (5 points) Write a function, reverse, that takes a string as a parameter and returns the reversed version of it. Function cal reverse("bat" reverse("Apple Pe Return value tab P elppA 4) (5 points) Write a function, string stats, that takes no parameters. It asks the user for an item, then prints out the number of vowels (a,ej.o,u), spaces, and consonants in the item. It continues asking the user for an item until the users input is blank. The items may contain spaces, which should not be included in either the vowel count or the consonant count This function should be case-insensitive. You should use the python str.lower O,str.upper), and/or str.count functions to help solve this problem. Note that this function terminates when the user presses enter without typing any input Function cal Output (printed, input in bold underlined Item? d Vowels: string stats paces: Vowels:1 Spacess tem? Vowels: Consonants: Ieem? 5) (5 points) Write a function, absolute day, that, given a year, month, and a day, retuns the absolute day of the year that day corresponds to. You may use the provided get days in month (year, month number) and calendar Ialeap(yearl to solve this problem. See provided code at the end of this write-up Function call absolute day (2019, 11 absolute day (2005, 3. 2) absolute day (20043, 2) Return value 62 6) (10 points) Write a function, days alive_loop, that, given a year, month, and a day representing a birthday, returns the number of days that person has been alive. You may use your absolute_day (year, month number) function, and the provided get_year ) get month and get_day) functions as well as calendar isleap (yearl to solve this problem. You must solve this problem using a while loop! Function call daya alive loop(2019, 2. 25) days alive loop (2018, 2. 10 daya alive loop(2000, . 30) Retum value (assuming that the current day is February 26th, 2019) 381 6876 7) (5 points) Write a function, days alive math, that, given a year, month, and a day representing a birthday, returns the number of days that person has been alive. You may use your absolute day (year, month number) function, and the provided get year O get month ,and get_day functions as well as calendax Leapdaya (heain year end year to solve this problem. You must solve this problem without using a while loop Function cal days alive math(2039, 2, 25) daya-alive-mat h (2018, 2# 10) daya-alive-mat h (2000, 4# 30) Retum value (assuming that the current day is February 26th, 2019) 383 6876 8) (5 points) Finally, write a main function in which you repeatedly ask the user for birthdays and print the number of days they have been alive until they type "done" Function call Output (as suming that the current day is February 26th, 2019) main Year7 201 Month? 2 Day? 25 That 'a 2 days Year? 1800 Month? 1 Day?1 That's 80044 days Year? dons Month? done

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions