CODE IN PYTHON
17. Use the Design Recipe to define a function called black_jack which consumes to 2 int values greater than 0. Return whichever value is nearest to 21 without going over. Return 0 if they both go over. Include a docstring!
Write three assertEqual statements to test your function.
import unittest
def black_jack(n1, n2):
if n1 > 21:
if n2 > 21:
return 0
return n2
elif n2 > 21:
return n1
else:
if n1 < n2:
return n2
else:
return n1
class BlackJackTest(unittest.TestCase):
def test_black_jack(self):
self.assertEqual(black_jack(19, 20), 20)
self.assertEqual(black_jack(14, 18), 18)
self.assertEqual(black_jack(23, 29), 0)
unittest.main()
CODE IN PYTHON 17. Use the Design Recipe to define a function called black_jack which consumes to 2...
In Python Use the Design Recipe to write a function factorial that when given a positive integer calculates the factorial. If given a negative integer or not an integer), the function should return None. If given 0, it should return 1. Include a docstring! Note: You may assume all arguments passed to this function will be numeric. Write three assertEqual statements to test your function. To test and receive credit for your assertEqual statements, copy them into Part E and...
Python Language !
Use the Design Recipe to define a function save_history which consumes two parameters, a nested list and an int representing the current landing attempt. The function should open a new file named LandingNN.csv' where NN is two digits representing the current landing attempt. The first line should contain the number of sublists in the nested list. Each sublists should be written to the file on its own line with its values separated by commas. This function should...
Python Use the Design Recipe to write a function called running_average that repeatedly asks the user to input integers at the keyboard until they type the word done. Return the average of the values they entered. You may assume the user will only enter integers or "done". Include a docstring!
Python Language
The Blip Blob New Year celebration started on a Tuesday. Use the Design Recipe to write a function called blip_blop_day that consumes an int representing the number of days that have passed since their celebration start day and returns name of the current day. For example, if 2 days have passed, then 'Thursday' should be returned. Include a docstring! For example: Test Result 2 Thursday 4 Saturday Monday Tuesday 6 7 8 Wednesday
Problem 20 [ 2 points ] Use the Design Recipe to write a function, print_histogram that consumes a list of numbers and prints a histogram graph using asterisks to represent each number in the list. Use one output line per number in the list. You may assume that only integers are passed to this function. Your function should ignore negative values. Include a docstring! Test Result print_histogram([ 0, 2, 4, 1]) ** **** * print_histogram([10, 5, 3, -1, 8]) **********...
Question 1 Assume a function called count_primes is pre-definied. If consumes two int arguments start and stop that returns the number of prime integers between start (inclusive) and stop (exclusive). Note: The start value must be less than or equal to the stop value. Enter 3 assertEqual statements to test the count_primes function. Question 2 Define a function called count_primes that consumes two int arguments start and stop that returns the number of prime integers between start (inclusive) and stop...
PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input. For example: Test Input Result print(yesOrNo()) hello blank...
Python Question: Define the function high_score that consumes a list of integers (representing scores in a game) and produces an integer representing the highest score in the list. Ignore scores less than 100, and stop processing values if you encounter -999. If the list is empty, return the value None instead. It is up to you to decompose this function (or not) however you want. Here is my code so far: from cisc108 import assert_equal def high_score(scores: [int])->int: max_num =...
in python
A. Define a function called contains_only_integers() that takes a tuple, returns True if all the items in the tuple are integers(2), and returns False otherwise. For example, contains_only_integers (3, 5, 17, 257, 65537) ), contains_only_integers( (-1,) ), and contains_only_integers( ) should all return True, but contains_only_integers (2.0,4.0)) and contains_only_integers (8, 4, "2", 1)) should both return false. Your function should use a while loop to do this calculation. 121 Hint: the is instance() built-in function provides the most...
python Define a function called print_values which takes a dictionary object as a parameter. The function should print all values in the dictionary. However, the order is based on the sorted keys in the dictionary. For example, if we have the following dictionary: {'b':36, 'a':12, 'c':24} The output is: 12 36 24 A faulty solution has been provided below. Identify the fault and submit a corrected version of this code. def print_values(dict1): for k in list(dict1.keys()).sort(): print(dict1[k], end=" ") For...