Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.) This function takes a bit of preparation first. Try entering the following in a shell: len (mumps) len (Yellow-bellied Sapsucker') len('') phrase = 'That

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

1.) This function takes a bit of preparation first. Try entering the following in a shell: len (mumps) len ("Yellow-bellied Sapsucker') len('') phrase = 'That is silly!' length = len (phrase) print (length) you just learned about the len function, write a function called word length that has two parameters. The first will be a string and the second will be an integer. The function first prints a message about the relationship between the length of the word and the integer, as shown in the following examples. Here are some examples of calling the function with different arguments. The code executed is in blue, the output produced is in green): word length('liversnaps', 7) Longer than 7 characters: liversnaps word length('earwax', 5) Longer than 5 characters: earwax word length('chickenfat', 10) Exactly 10 characters: chickenfat word length('Gross!', 13) Shorter than 13 characters: Gross! 2.) Write a function called stop light that determines whether a stop light should change color and, if so, what color it should change to. It takes two arguments. The value of the first will be either "green", "yellow", or "red". This represents the stop light's current color. The second parameter tells the function how long this color has been showing. If green has been showing longer than 60 seconds, return "yellow". If yellow has been showing longer than 5 seconds, return "red". If red has been showing longer than 55 seconds, return "green". If the color hasn't been showing long enough (e.green has been showing for 17 seconds), return the current color. Here are some examples of calling the function with different arguments. (The code executed is in blue, the value returned by the function is in green): stop light('green', 61) stop light (yellow', 5) stop light (yellow', 6) stop light('red', 12) stop light('red', 56) --> --> --> --> "yellow red "red 'green' 3.) Write a function called is normal_blood pressure that has two integer parameters. The first represents systolic blood pressure (the top number in a blood pressure reading). The second represents diastolic blood pressure (the bottom number in a blood pressure reading) The function should return true if systolic is less than 120 and diastolic is less than 80 i.e. blood pressure is normal). Otherwise it returns False Here are some examples of calling the function with different arguments. (The code executed is in blue, the value returned by the function is in green): is_normal_blood pressure (120, BO) is normal blood pressure (119, 80) is normal blood pressure (119, 79) 1s normal blood pressure (120, 79) --> --> --> --> False False True False 4) Write a function called doctor that has no parameters. The function will ask the user to enter his/her systolic blood pressure reading. It will then ask for the diastolic reading. The function then prints either "Your blood pressure is normal." or "Your blood pressure is high." depending on the values entered. This function should use the function you wrote in the previous question Here are some examples of calling the function with different arguments. The code executed is in blue, the output produced is in green, and user input is in red): doctor() Enter your systolic reading: 119 Enter your diastolie reading: 79 Your blood pressure is normal. doctor() Enter your systolie reading: 133 Enter your diastolic reading: 79 Your blood pressure is high. 5.) Write a function called pants_size that has a single parameter (the value will be an integer) representing a person's waist size in inches. The function returns a string. The string retumed will be either "small","medium", or "larde" depending on the parameter value. Waist measurements that are 34 inches or larger should return large. Measurements that are 30 inches or larger, but not large enough to be in the large category, should return medium. Anything smaller should return small Here are some examples of calling the function with different arguments. The code executed is in blue, the value returned by the function is in green): "large 3 --> pants size (38) pants size (34) pants size (33) pants size (29) pants site (-20) pants size (2000) "large medium small 'small "large --> --> 6) Write a function called pants fitter that takes no arguments. The function should first ask the user for his/her name. It then greets the user by name. Next it asks the user for his/her waist size in inches (a positive integer). It then asks the user how many pairs of pants he/she would like to buy a positive integer). Next it asks what type of pants the user wants to buy leither "regular" or "fancy"), Next it calculates the cost of the pants (integer). Regular pants cost $40 per pair Fancy pants cost $100 per pair. Finally it prints out the number of pairs, the size, the type, and the total cost. The following examples show the format that your prompts and outout should be in. This function should use the function you wrote in the previous question Here are some examples of calling the function with different arguments. The code executed is in blue, the output produced is in green, and user input is in red): 7.1 Write a function called diadug that takes a single argument number (assume it will always be a positive integer). For every integer from 1 up to and including number, the function will print a message if warranted. If the integer is evenly divisible by the function will print "dig" If the integer is evenly divisible by Sit prints "dua" If the integer is evenly divisible by both 3 and 5 it prints "digdug". If the integer is not divisible by either Jor 5 it does not print anything Here are some examples of calling the function with different arguments. The code executed is in blue, the output produced is in green digdug (2) digdu (3) 3: dig digdug (5) digdug (15) 9 dig 10 dug 12 : da 12 dig 15 : digdug 8.) Write a function called beef_type that takes a single parameter, percent lean. If the value of percent lean is less than 78%, return "Hamburger". If it is at least 78% and less than 85%, then return "Chuck". At least 85% but less than 90% return "Round". 90-95% inclusive return "Sirloin". If percent lean doesn't fall within one of these ranges, return "Unknown". Here are some examples of calling the function with different arguments. The code executed is in blue, the value returned by the function is in green): "Sirloin "Chuck beef_type (91.2) beef_type(78) beef_type (87) beef_type(95.1) --> --> --> "Round" "Unknown 9.] Write a function called species height that takes arguments. The first is either "Human" or "Klingon". The second is a positive float representing the height in inches) of this human or Klingon. In this homework assignment, the average human height is 67 inches. The average Klingon height is 71 inches. For the parameters given, print out if it is above, below or at the average height for its species. Here are some examples of calling the function with different arguments. The code executed is in blue, the output produced is in green): 62.1) species height (Human Below Average species height (Klingon", 73) Above Average species height("Klingon ", 71) Average 10.) Write a function called sooner date that has 4 integer parameters. The first is a number between 1 and 12 (inclusive) that represents a month. 1 is January, 2 is February, etc. The second is a number between 1 and 31 (inclusive) that represents a day. The third parameter is another integer representing a month and the fourth is another integer parameter representing a day. So essentially you have 2 dates (the first 2 parameters and the second 2 parameters). Figure out which date would come sooner, then print out that date in the format month / day Here are some examples of calling the function with different arguments. The code executed is in blue, the output produced is in green): sooner date(1, 1, 1, 2) 1 / 1 sooner_date (2, 5, 1, 3) 1 / 3 sooner_date(8, 25, 7, 30) 7 / 30

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

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions

Question

Identify and describe three factors in group attraction.

Answered: 1 week ago

Question

please provide the step by step answer.

Answered: 1 week ago