Design a function called print_area that takes two floating-point numbers, representing the length and width of a rectangle. The print_area function calculates and prints the area of the rectangle, rounded to two decimal places.
Design a function called small_enough_word that takes a string for which the number of characters will be tested, and an integer representing the maximum allowable number of characters that the word can contain. Remember: the arguments MUST be in this order (the string of text before the number of characters limit). The function should compare the length of the string (the total number of characters) with the number:
If the length of the word is greater than the number, the
function should print:
“Error: X characters too large” where X is how many characters
above the number the length of the string is.
If the number of characters in the string is less than or equal to the number: “Y is perfectly valid” should be printed, where Y is the word.
Design a function called print_num_odd that takes three integer numbers as arguments. The function must print out how many of the integers are odd numbers. The output will be:
“X odd numbers were found” where X is either 0, 2, or 3. The function will print “1 odd number was found” if only a single one of the integers was an odd number.
# assignment2.py # # Student name: # Student id: V00 def main(): print('Assignment 2') ''' Complete this assignment by doing the following for each function: - uncommenting one test function call in main NOTE: each test function has at least one test, but you should add additional tests to ensure the correctness of your functions - complete a full function design for each function (write the documentation and define the function) NOTE: follow the documentation provided for implementing each function in the assignment2.pdf - process to the next function by doing the steps outlined above until all functions are designed with proper documentation, implemention and testing ''' test_print_dog_years() #test_print_area() #test_print_average() #test_small_enough_word() #test_print_max() #test_print_num_odd() def test_print_dog_years(): print_dog_years(0) # expects 0 print_dog_years(3) # expects 21 print_dog_years(8) # expects 56 # (int -> None) # prints the given human age in dog years def print_dog_years(age): # fix the function so it produces expected output print(0) def test_print_area(): print_area(0.0, 0.0) # expects 0.00 # TODO: add tests # TODO: complete function design of print_area def test_print_average(): print_average(0.0,0.0,0.0) # expects 0.0 # TODO: add tests # TODO: complete function design of print_average def test_small_enough_word(): # expects: "Error: 2 characters too large" small_enough_word("anthony", 5) # TODO: add tests # TODO: complete function design of small_enough_word def test_print_max(): print_max(0,0,0) # expects 0 # TODO: complete function design of print_max def test_print_num_odd(): # expects "0 odd numbers were found" print_num_odd(0,0,0) # TODO: complete function design of print_num_odd # The following code will call your main function # It also allows our grading script to call your main # DO NOT ADD OR CHANGE ANYTHING PAST THIS LINE # DOING SO WILL RESULT IN A ZERO GRADE if __name__ == '__main__': main()
CODE IN PYTHON:
def print_area(width,height):
area = width * height
print("The area is:",area)
def small_enough_word(str,n):
size = len(str)
if(size>n):
print(size-n," characters too large")
else:
print(str+" is perfectly valid...");
def print_num_odd(a,b,c):
count = 0
if(a%2==0):
count += 1
if(b%2==0):
count += 1
if(c%2==0):
count += 1
if(count==1):
print("1 odd number was found")
else:
print(str(count)+" odd numbers were found")
small_enough_word("anthony",5)
print_area(10.0,8.0)
print_num_odd(1,6,3)
INDENTATION:
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.