Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please implement the 6 functions and name the source file as h1.py. py-test has been provided Problems 1. A function change() that accepts a number

please implement the 6 functions and name the source file as h1.py. py-test has been provided image text in transcribed
image text in transcribed
image text in transcribed
Problems 1. A function change() that accepts a number of U.S. cents and returns a tuple containing, respectively, the smallest number of U.S. quarters, dimes, nickels, and pennies that equal the given amount >>> change (96) ( 3, 2, 0, 1) >>> change(8) ( 0, 0, 1, 3) >>> change(-4) RangeError: amount cannot be negative >>> change (33.25) ( 1, 0, 1, 3.25 ) 2. A function strip_quotes() that accepts a string and returns a new string equivalent to the argument but with all single quotes and double quotes removed. \'to\"\"\"\"**'z') >>> strip_quotes('a\"\ 'atoz' 3. A function scramble() that randomly permutes a string. What does random mean? It means that each time you call the function for a given argument, all possible permutations are equally likely. Random is not the same as arbitrary, >>> scramble('Hello, world') "lo,Hll erwdo' >>> scramble('Hello, world') 'rewllh,ool d' 4. A generator function powers() that yields successive powers of a base starting at 1 and going up to some limit. >>> powers (2, 70) [1, 2, 4, 8, 16, 32, 64) 5. A function triples() returning a list of all (positive) integer Pythagorean triples for all hypotenuse values up to, and including, some value. >>> triples (40) [(3, 4, 5), (5, 12, 13), (6, 8, 10), (7, 24, 25), (8, 15, 17), (9, 12, 15), (10, 24, 26), (12, 16, 20), (12, 35, 37), (15, 20, 25), (15, 36, 39), (16, 30, 34), (18, 24, 30), (20, 21, 29), (21, 28, 35), (24, 32, 40)] 6. A"chainable" function say that accepts one string per call, but when called without arguments, returns the words previously passed, in order, separated by a single space. >>> say('Hello') ('my') ('name') ('is')('Colette')(); "Hello my name is Colette' h1_test.py import re import math import pytest from hi import (change, strip_quotes, scramble, say, triples, powers) def test_change(): assert change(0) -- (0, 0, 0, 0) assert change(97) = (3, 2, 0, 2) assert change(8) -- (@, e, 1, 3) assert change (250) -- (10, @, , ) assert change (144) = (5, 1, 1, 4) assert change (97) = (3, 2, 2, 2) assert change ( 100000000000) = (4000000000, 0, 0, 0); with pytest.raises (ValueError) as excinfo: change(-50) assert str(excinfo.value) == 'amount cannot be negative' def test_strip_quotes(): assert strip_quotes( ) ! assert strip_quotes('Hello world') - 'Hello, world

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

More Books

Students also viewed these Databases questions