Question
Can someone please help me with this project. Exact code (picture) is preferred for easy translation and practice. Pay close attention to the return value
Can someone please help me with this project. Exact code (picture) is preferred for easy translation and practice.
Pay close attention to the return value for each function, as per the project specification. Programming style is important! Remember to Use whitespace between operators and operands Use descriptive variable names Add appropriate comments.
(1) Rock, Paper, Scissors
Start with the Rock, Paper, Scissors program that we talked about in class on week 6 (see posted class notes for week 6). Add a docstring, then add code to ask a player whether they would like to play the game (use Python input function), and execute the game code, or not, based on the answer. Finally, add code to allow players to play repeatedly (that is, at the end of each game, ask whether they would like to play again and execute the game code, or not, based on the answer).
(2) Include at least three additional test cases for the following count_vowels, find_min_max, and my_average functions
Note: Where examples for testing are needed, be sure to include input, and boundary input, e.g., 0, 1, empty strings, etc. (I will elaborate on this topic on Monday).
(2a) The following function is broken. The docstring describes what it is supposed to do.
def count_vowels(s):
'''
(str) -> int
Return number of vowels in s.
>>> count_vowels('The quick brown fox')
5
''' vowels = 'aeiou'
ctr = 0
for ch in s:
if ch in vowels:
counter += 1
return ctr
Fix the bug(s) in the current version of count_vowels. Comment any code you change. Generate a series of examples to test count_vowels
(2b) The following function is broken. The docstring describes what it is supposed to do.
def find_min_max(values):
''' (string) -> None
Find the maximum and minimum values in a non-empty string of digits and print them.
None value is returned.
>>> find_min_max('45312')
The minimum value is 1.
The maximum value is 5.
>>> find_min_max('428')
The minimum value is 2.
The maximum value is 8.
'''
mmin = 0
mmax = 0
for value in values:
if value > mmax:
mmax = value
if value < mmin:
mmin = value
print('The minimum value is', mmin)
print('The maximum value is', mmax)
#or
#print('The minimum value is {}'.format(mmin))
#print('The maximum value is {}'.format(mmax))
return None
Fix the bug(s) in the current version of find_min_max. Comment any code you change. Generate a series of examples to test find_min_max.
(2c) Suppose you have a data set of customer satisfaction survey results, with product ratings from 1 (poor quality) to 9 (high quality). Zeros indicate no answer. Here is a function that computes and returns the average product rating from the data set, a function parameter of type string. Zeros do not count toward the average. For no usable data, return 0.
The following function is broken. The docstring describes what it is supposed to do.
def my_average(dataset):
'''
(string) -> float
returns average of values in input string values, but zeros do not count at all
>>> my_average('23')
2.5
>>> my_average('203')
2.5
'''
count = 0
total = 0
for value in dataset:
if value != '0':
total += int(value)
count += 1
avg = total / count
return avg
Fix the bug(s) in the current version of my_average. Comment any code you change. Generate a series of examples to test my_average.
(3) As Time Goes By with bugs Oh, no someone started trying to improve working code without making a copy of the working version first. Now function minutesToYears is not returning the correct result. Find and fix the bugs in minutesToYears and/or its auxiliary functions. The revised functions should work for all of the examples given in the docstrings.
Comment any changes you make in the code.
def minutesToHours(minutes):
'''
(number) -> float
convert input minutes to hours;
return hours
>>> minutesToHours(60)
1.0
>>> minutesToHours(90)
1.5
>>> minutesToHours(0)
0.0
'''
hours = minutes / 60
hours = round(hours, 2)
print(hours)
return None
def hoursToDays(hours):
'''
(number) -> float
convert input hours to days; return days
>>> hoursToDays(24)
1.0
>>> hoursToDays(100)
4.17
>>> hoursToDays(0)
0.0
'''
days = hours / 24
return days
def daysToYears(days):
'''
(number) -> float
convert input days to years; return years
>>> daysToYears(365)
1.0
>>> daysToYears(100)
0.27
>>> daysToYears(0)
0.0
'''
days = 365
years = days / 365
years = round(years, 2)
return years
def minutesToYears(m):
'''
(int) -> float
input number m minutes is converted to equivalent number of years. return years. call auxiliary functions to do each step.
>>> minutesToYears(525600)
1.0
>>> minutesToYears(5256000)
10.0
>>> minutesToYears(394200)
0.75
>>> minutesToYears(0)
0.0
'''
minutesToHours(m)
hoursToDays(h)
daysToYears(d)
return y
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started