Write a program to create basic functions for computation in python language.
Requirements and Specifications
(Some of these exercises require written answers to questions. Answer those and copy and paste those answers to the bottom of the source file to which they apply).
This lab contains detailed information about functions as well as exercises using functions. Be sure to read through the entire lab. If you have any questions let me know.
Introduction to programmer-defined functions
We can write our basic functions to perform some computations. These types of functions are referred to as programmer-defined functions. A programmer-defined function may have three parts: 1) Function definition, 2) Function Call, and/or 3) Function declaration.
QUESTION 1# Create function that takes temperature, wind speed and humiditydef getWeatherMessage(temp, humidity, windspeed):F = temph = humidityv = windspeedweather_message = "Weather not known"# First condition: good weather# Temperature between 65 and 75, humidity below 50% and windspeed less than 10if F >= 65 and F <= 75 and h < 50 and v < 10:weather_message = "It is a good weather day"# Second condition: bad weather# Temperature above 85 or below 45, humidity above 80 or wind speed > 20elif F > 85 or F < 45 or h > 80 or v > 20:weather_message = "It is a bad weather day"else:weather_message = "It is just another day"return weather_messagetempNow = float(input("What is the temperature in Fahrenheit?"))humidityNow = float(input("What is the humidity in %?"))windspeedNow = float(input("What is the windspeed in miles/hour?"))weather = getWeatherMessage(tempNow, humidityNow, windspeedNow)print(weather)QUESTION 2def isExpired(months, decayrate):# Express decayrate as a ratio between 0 and 1r = decayrate/100.0# Now, create a loop from 1 to monthscurrent_potency = 1for i in range(months):current_potency = current_potency*(1-r)# if the potency is less than 0.5, the drug is expiredif current_potency < 0.5:return Trueelse:return False# Testprint(isExpired(10,10)) # Should print Trueprint(isExpired(15,4)) # Should print FalseQUESTION 3def NominalGrade(Ascore, Escore):final_score = (Ascore + Escore)/2.0 # Average between both scoresif final_score >= 86:return 4elif final_score >= 74 and final_score < 86:return 3elif final_score >= 62 and final_score < 74:return 2elif final_score >= 50 and final_score < 62:return 1elif final_score >= 0 and final_score < 50:return 0def TrueGrade(Ascore, Escore):# Get NominalGradenominal = NominalGrade(Ascore, Escore)# Get letter grade from exam onlyexam_grade = NominalGrade(Escore, Escore)# If the nominal is higher than exam_grade in 2 units, decrease nominal by 1if nominal > exam_grade + 1:nominal -= 1letter_grades = ['F', 'D', 'C', 'B', 'A']return letter_grades[nominal]# Testprint(TrueGrade(96, 84)) # Should return Aprint(TrueGrade(96,54)) # Should return CQUESTION 4def NumRepeats(num1, num2, num3):# Add the items to a set. This will also work with integersitems = set([num1, num2, num3])# Now, count the lenth of the set.# If the set has length == 3, it means that all 3 items are differentif len(items) == 3:return 0# If the length of the set is equal to 2, it means one of the items is repeatedelif len(items) == 2:return 1# If the length of the set is equal to 1, it means that all items are equalelif len(items) == 1:return 2# Testprint(NumRepeats(5, 9, 4)) # Should return 0print(NumRepeats(5,9,5)) # Should return 1print(NumRepeats(5,5,5))# Should return 2# Test with stringsprint(NumRepeats('A', 'B', 'C')) # Should return 0print(NumRepeats('A', 'B', 'A')) # Should return 1print(NumRepeats('A', 'A', 'A')) # Should return 2