implement function 2 in python. name the source file as h1.py. A test file h1_test.py is provided below!
h1_test.py
import re
import math
import pytest
from h1 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) == (0, 0, 1, 3)
assert change(250) == (10, 0, 0, 0)
assert change(144) == (5, 1, 1, 4)
assert change(97) == (3, 2, 0, 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'
assert strip_quotes('"\'') == ''
assert strip_quotes('a"""\'\'"z') == 'az'
def test_scramble():
for s in ['a', 'rat', 'JavaScript testing', '', 'zzz', '^*))^*>^▱ÄÈËɡɳɷ']:
assert sorted(s) == sorted(scramble(s))
possibilities = set(['ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA'])
for _ in range(200):
possibilities.discard(scramble('ABC'))
assert not possibilities
def test_say():
assert say() == ''
assert say('hi')() == 'hi'
assert say('hi')('there')() == 'hi there'
assert say('hello')('my')('name')('is')('Colette')() == 'hello my name is Colette'
def test_triples():
assert triples(0) == []
assert triples(5) == [(3, 4, 5)]
assert set(triples(40)) == set([(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)])
def test_powers():
p = powers(2, 10)
assert next(p) == 1
assert next(p) == 2
assert next(p) == 4
assert next(p) == 8
with pytest.raises(StopIteration):
next(p)
assert list(powers(2, -5)) == []
assert list(powers(7, 0)) == []
assert list(powers(3, 1)) == [1]
assert list(powers(2, 63)) == [1, 2, 4, 8, 16, 32]
assert list(powers(2, 64)) == [1, 2, 4, 8, 16, 32, 64]

SOURCE CODE IN PYTHON:
#function that accepts a string and returns a new string
#with single quotes and double quotes removed
def strip_quotes(s):
new_s='' #creating new string
for i in s: #iterating through the string
if i!='\'' and i!='\"': #if character is not quotes
new_s+=i #we add it to new string
return new_s #returning new string
#testing the function
assert strip_quotes('') == ''
assert strip_quotes('Hello, world') == 'Hello, world'
assert strip_quotes('"\'') == ''
assert strip_quotes('a"""\'\'"z') == 'az'
print('Test cases passed!')

OUTPUT:

implement function 2 in python. name the source file as h1.py. A test file h1_test.py is...
(Python)Implement the function deep_list, which takes in a list, and returns a new list which contains only elements of the original list that are also lists. Use a list comprehension. def deep_list(seq): "" "Returns a new list containing elements of the original list that are lists. >>> seq = [49, 8, 2, 1, 102] >>> deep_list(seq) [] >>> seq = [[500], [30, 25, 24], 8, [0]] >>> deep_list(seq) [[500], [30, 25, 24], [0]] >>> seq = ["hello", [12, [25], 24],...
IN PYTHON Implement a function printSeqs() that accepts a list of name lst and prints the following sequences. The sequences are printed by the for loops found in the function. The information below shows how you would call the function printSeqs() and what it would display: Write a for loop that iterates through a list of names and print a greeting for each name in the list. Request from the user a positive integer n and prints all the positive...
Python 3, nbgrader, pandas 0.23.4
Q2 Default Value Functions (1 point) a) Sort Keys Write a function called sort_keys, which will return a sorted version of the keys from an input dictionary Input(s): dictionary :dictionary reverse boolean, default: False Output(s): .sorted_keys: list Procedure(s) Get the keys from the input dictionary using the keys()method (this will return a list of keys) Use the sorted function to sort the list of keys. Pass in reverse to sorted to set whether to reverse...
Exercise 1: BSTree operations For this exercise you'll implement three additional methods in the binary search tree data structure completed in class, so that you have an opportunity to practice both using the recursive pattern covered in class and navigating the binary tree structure. The methods you'll implement are: count_less_than: takes an argument x, and returns the number of elements in the tree with values less than x successor: takes an argument x, and returns the smallest value from the...
IN PYTHON the original problem was Design (pseudocode) and implement (source code) a program (name it WeeklyHours) to compute the total weekly hours for 3 employees. The program main method defines a two-dimensional array of size 3x7 to store employers’ daily hours for the week. Each row represents one employee and each column represent one day of the week such that column 0 designates Monday, column 1 designates Tuesday, etc. The program main method populates the array with random numbers...
using Python --- from typing import List THREE_BY_THREE = [[1, 2, 1], [4, 6, 5], [7, 8, 9]] FOUR_BY_FOUR = [[1, 2, 6, 5], [4, 5, 3, 2], [7, 9, 8, 1], [1, 2, 1, 4]] UNIQUE_3X3 = [[1, 2, 3], [9, 8, 7], [4, 5, 6]] UNIQUE_4X4 = [[10, 2, 3, 30], [9, 8, 7, 11], [4, 5, 6, 12], [13, 14, 15, 16]] def find_peak(elevation_map: List[List[int]]) -> List[int]: """Return the cell that is the highest point in the...
Write a Python program stored in a file q3.py that asks for the prices of items and your money amount as input, and prints the options of items along with cost as output. Enter list of prices : 7 3 9 12 26 17 8 9 Enter dollar amount : 16 You have total 8 options Option 1: You can buy item 1 and item 2 with $10 .0. Option 2: You can buy item 1 and item 3 with...
Q1. Write a program to simulate a grocery waiting queue. Your
program should ask the user if they want to add a customer to the
queue, serve the next customer in the queue, or exit. When a
customer is served or added to the queue, the program should print
out the name of that customer and the remaining customers in the
queue.
The store has two queues: one is for normal customers, another is
for VIP customers. Normal customers can...
[PYTHON]
Objective Complete the function definitions generateRandomPoint,isIncircle, and ApproximatePI generateRandomPoint(): Returns a list (x,y) where x and y are uniformly sampled from the range [0,4 isIncircle(x,y): Returns True if p is in the circle; otherwise, False (Note: The point p is in the circle if its distance from the center of the circle is less than or equal to the radius of the circle.) ApproximatePI (n): Generates n random points within the square and returns 4 P(A) Example #1 Input:...
using this functiondef num_permutation_sequence(n):these are the test casesg = num_permutation_sequence(3)assert (next(g), next(g), g.send(0), next(g), next(g), next(g),g.send(0)) == (1, 3, 4, 12, 24, 24, 120)Exercise (Challenge) Extend the function num_permutation_sequence(n) so that calling send(o) method causes the generator to increment n instead of k for the next number to generate. i.e., for 0 <k <n, send(O) . Pn,k-1 ? Pnik Pn+1,6 ? Pn+1,5+1 (7) where without labels is the normal transition without calling the send method. Hint: n + 1 Pn+1,6...