Create a new program in Mu and save it as ps4.3.3.py and take the code below and fix it as indicated in the comments:
# Imagine you're writing some code for an exercise tracker.
# The tracker measures heart rate, and should display the
# average heart rate from an exercise session.
#
# However, the tracker doesn't automatically know when the
# exercise session began. It assumes the session starts the
# first time it sees a heart rate of 100 or more, and ends
# the first time it sees one under 100.
#
# Write a function called average_heart_rate.
# average_heart_rate should have one parameter, a list of
# integers. These integers represent heart rate measurements
# taken 30 seconds apart. average_heart_rate should return
# the average of all heart rates between the first 100+
# heart rate and the last one. Return this as an integer
# (use floor division when calculating the average).
#
# You may assume that the list will only cross the 100 beats
# per minute threshold once: once it goes above 100 and below
# again, it will not go back above.
# Add your function here!
# Below are some lines of code that will test your function.
# You can change the value of the variable(s) to test your
# function with different inputs.
#
# If your function works correctly, this will originally
# print 114 (because there are 14 measurements from 102 to
# 101, their sum is 1609, and 1609 // 14 is 114).
beats = [72, 77, 79, 95, 102, 105, 112, 115, 120, 121, 121,
125, 125, 123, 119, 115, 105, 101, 96, 92, 90, 85]
print(average_heart_rate(beats))# Imagine you're writing some code for an exercise tracker.
# The tracker measures heart rate, and should display the
# average heart rate from an exercise session.
#
# However, the tracker doesn't automatically know when the
# exercise session began. It assumes the session starts the
# first time it sees a heart rate of 100 or more, and ends
# the first time it sees one under 100.
#
# Write a function called average_heart_rate.
# average_heart_rate should have one parameter, a list of
# integers. These integers represent heart rate measurements
# taken 30 seconds apart. average_heart_rate should return
# the average of all heart rates between the first 100+
# heart rate and the last one. Return this as an integer
# (use floor division when calculating the average).
#
# You may assume that the list will only cross the 100 beats
# per minute threshold once: once it goes above 100 and below
# again, it will not go back above.
# Add your function here!
def average_heart_rate(beats):
s = 0
c = 0
for i in beats:
if i >= 100:
s +=i #s is for adding the heartbeats above 100
c += 1 #c is for keep count of number of heartbeats after it starts
if c>0 and i<100: #if we get a value less than 100 after exercise we stop it
break
avg = s // c #floor division to calculate average
return avg
# Below are some lines of code that will test your function.
# You can change the value of the variable(s) to test your
# function with different inputs.
#
# If your function works correctly, this will originally
# print 114 (because there are 14 measurements from 102 to
# 101, their sum is 1609, and 1609 // 14 is 114).
beats = [72, 77, 79, 95, 102, 105, 112, 115, 120, 121, 121,
125, 125, 123, 119, 115, 105, 101, 96, 92, 90, 85]
print(average_heart_rate(beats))
Output after executing:

Create a new program in Mu and save it as ps4.3.3.py and take the code below...
Create a new program in Mu and save it as ps3.3.3.py and take the code below and fix it as indicated in the comments: mystery_int = 46 # You may modify the lines of code above, but don't move them! # When you Submit your code, it should work with # different values for the variables. # Use a while loop to create a countdown from mystery_int to # 0. Count down by 3s: if mystery_int is 46, then you...
Create a new program in Mu and save it as ps3.4.1.py and take the code below and fix it as indicated in the comments: # Write a function called hide_and_seek. The function should # have no parameters and return no value; instead, when # called, it should just print the numbers from 1 through 10, # follow by the text "Ready or not, here I come!". Each # number and the message at the end should be on its own...
Create a new program in Mu and save it as ps4.5.1.py and take the code below and fix it as indicated in the comments: # Write a function called phonebook that takes two lists as # input: # # - names, a list of names as strings # - numbers, a list of phone numbers as strings # # phonebook() should take these two lists and create a # dictionary that maps each name to its phone number. For #...
Create a new program in Mu and save it as ps3.4.2.py and take the code below and fix it as indicated in the comments: # A year is considered a leap year if it abides by the # following rules: # # - Every 4th year IS a leap year, EXCEPT... # - Every 100th year is NOT a leap year, EXCEPT... # - Every 400th year IS a leap year. # # This starts at year 0. For example:...
Create a new program in Mu and save it as ps2.4.1.py Take the code below and fix it as indicated in the comments: dividend = 7 divisor = 3 # You may modify the lines of code above, but don't move them! # Your code should work with different values for the variables. # The variables above create a dividend and a divisor. Add # some code below that will print the quotient and remainder # of performing this operation....
Create a new program in Mu and save it as ps4.3.1.py and take the code below and fix it as indicated in the comments: # Write a function called grade_scantron. grade_scantron should # take as input two lists: answers and key. Each list contain # strings. Each string will be only one letter, a character # from A to E. grade_scantron should return how many questions # the student got "right", where a student gets a question # right if...
Create a new program in Mu and save it as ps3.4.3.py and take the code below and fix it as indicated in the comments: # Consult this blood pressures chart: http://bit.ly/2CloACs # # Write a function called check_blood_pressure that takes two # parameters: a systolic blood pressure and a diastolic blood # pressure, in that order. Your function should return "Low", # "Ideal", "Pre-high", or "High" -- whichever corresponds to # the given systolic and diastolic blood pressure. # #...
Create a new program in Mu and save it as ps4.4.1.py and take the code below and fix it as indicated in the comments: # Write a function called "save_leaderboard" that accepts a # single list of tuples as a parameter. The tuples are of the # form (leader_name, score) # The function should open a file called "leaderboard.txt", # and write each of the tuples in the list to a line in the file. # The name and score...
Create a new program in Mu and save it as ps4.2.2.py and take the code below and fix it as indicated in the comments: # Write a function called "in_parentheses" that accepts a # single argument, a string representing a sentence that # contains some words in parentheses. Your function should # return the contents of the parentheses. # # For example: # in_parentheses("This is a sentence (words!)") -> "words!" # # If no text appears in parentheses, return an...
Create a new program in Mu and save it as ps2.4.3.py Take the code below and fix it as indicated in the comments: Level = 50 Attack = 125 Defense = 110 Power = 60 Modifier = 1 # You may modify the lines of code above, but don't move them! # Your code should work with different values for the variables. # In the Pokemon game franchise, damage is calculated using this formula found here: # https://bulbapedia.bulbagarden.net/wiki/Damage # #...