Question: this is in python and it states that it shouldn't need if/else logic or nested loops -- thank you ! 2. The function replace(s, old_ch,

this is in python and it states that it shouldn't need if/else logic or nested loops -- thank you !this is in python and it states that it shouldn't need if/elselogic or nested loops -- thank you ! 2. The function replace(s,

2. The function replace(s, old_ch, new_ch) will process the string s and replace all occurrences of character old_ch with the character new_ch. You will use a string variable to hold the accumulation, and concatenate characters into it one by one inside the loop. For example: >>> replace('hello, world!', 'l','w') 'hewwo, worwd!' >>> replace('we love chocolate', 'o','a') 'we lave chacalate' HINT: As you go through the string one character at a time, you will need some decision logic to evaluate each character, and to decide whether to use it in the accumulator (the string you are building), or replace it with new_ch. It might be helpful to begin by printing each character (one per line), and then print whether to "keep or replace it - this will help you visualize how the loop is operating. Make sure to comment-out the print statements when you've got it working, and be sure to have your function return the result. 3. The function calculate_average () must calculate collect inputs from the keyboard, calculate and print out the average of those inputs. Here is a sample run: This program will compute the average of numerical observations. How many observations do you have? 4 Enter next value: 95 Enter next value: 90 Enter next value: 99 Enter next value: 93 The average is 94.25. Your function must take inputs using the input function, and be prepared to handle both integer and floating-point values. You will begin by asking the user how many inputs they have, and then use a loop to collect that number of values. After the loop, you should print out the average with 2 digits of precision after the decimal place. Finally, the function must return the average (as well as having printed it with formatting). Test your work thoroughly! Put your test cases in the main section at the bottom of your file, i.e., if __name__ == ' __main__': print('sum_of_range (1,5,1)', sum_of_range (1,5,1)) print('sum_of_range (5,15,2)', sum_of_range (5,15,2)) print(calculate_average())

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!