Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This week's lab is an exercise in writing fairly straightforward functions. You guys are supposed to submit one py file with these several functions. When

image text in transcribed

This week's lab is an exercise in writing fairly straightforward functions. You guys are supposed to submit one py file with these several functions. When you try to test a function you write, just call the function and see if the return value is correct, but when you are submitting you lab, remember to comment these lines. Also, remember the docstrings; points will be deducted for missing docstrings. Here are the requirements of these functions 1. Write a function called 'avg3" which has 3 inputs, returns the average of these 3 input parameters. No need to check or convert input types 2. Write a function prod(start, stop)", returns the product of the integers start through stop inclusive. Eg, if we call prod(3,5). it should return 60 as 3x4x5. You may assume the inputs are integers. 3. Write a function called "pi approximate which has one input n, an integer, and use the following formula to calculate a famous approximation of pi: if n0, return 0. Else return the sum of first n terms of the approximation 4/1-4/3 + 4/5-4/7 + 4/9-E.g, if n-2, then the result should be 4/1-4/3, that is approximately 2.67. You may just return the long decimal Python gives you, such as 2.666666666666667; you don't need to calculate the fractional number or truncate the decimals. You are required to use at least one for loop in your function and you may not use any while loops. 4. Write a function 'word_count(st)" returns the number of words in string st, where a 'word" is any sequence of non-whitespace & #3356" so word count is 6 characters. Eg, if st "The number is #3364 & #3356 , then words are "The", "number", is, .#3364 Hint: Remember the string method isspace0 and remember that it tells if a string is entirely whitespace. text file. we prints on one line, the number of lines, the number of words, and the number of characters in the file (three numbers separated by tabs). Hint: Use word.count as a subroutine 5. Write a function called "wc', which stands for word count (a unix utility). wc takes one string as input, which should be the name of a 0/90 i nh on Noy 13; Exercise in writing fairly straightforward functions

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions