Question

Design a function called print_area that takes two floating-point numbers, representing the length and width of...

  1. 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.

  2. 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.

  3. 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()

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Design a function called print_area that takes two floating-point numbers, representing the length and width of...
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.
Program Instructions Write a program called censor.py. This program will have the following functionality and requirements:...
Program Instructions Write a program called censor.py. This program will have the following functionality and requirements: Has a main function: That asks the user to input a sentence Then asks the user to enter a list of words they want to replace (separated by spaces) Calls a function called replaceMultiWords passing those two parameters, which returns a filtered string Prints out the filtered (censored) string to the console Has a replaceMultiWords function that: Takes a string "sentence" and a string...
Write a function called score that meets the specifications below. def score(word, f): """ word, a...
Write a function called score that meets the specifications below. def score(word, f): """ word, a string of length > 1 of alphabetical characters (upper and lowercase) f, a function that takes in two int arguments and returns an int Returns the score of word as defined by the method: 1) Score for each letter is its location in the alphabet (a=1 ... z=26) times its distance from start of word. Ex. the scores for the letters in 'adD' are...
This is function.py def processString(string): # Implement this function This is # This should print 4.5...
This is function.py def processString(string): # Implement this function This is # This should print 4.5 3.0 processString("An example. Two") # This should print 4.4 5.3 4.5 processString("This is the first sentence. The second sentence starts after the period. Then a final sentence") Download function.py and complete the processString(string) function. This function takes in a string as a parameter and prints the average number of characters per word in each sentence in the string. Print the average character count per...
def processString(string): # Implement this function # This should print 4.5 3.0 processString("An example. Two") #...
def processString(string): # Implement this function # This should print 4.5 3.0 processString("An example. Two") # This should print 4.4 5.3 4.5 processString("This is the first sentence. The second sentence starts after the period. Then a final sentence") This function takes in a string as a parameter and prints the average number of characters per word in each sentence in the string. Print the average character count per word for each sentence with 1 decimal precision(see test cases below).-Assume a...
Write a cencrypt() function that takes a arbitrary length string and an integer as inputs and...
Write a cencrypt() function that takes a arbitrary length string and an integer as inputs and returns a string as output. The cencrypt() function you write in lab today needs to work on strings that contain upper-case letters, lower-case letters, or both. The output string should be all upper-case letters. (The Romans of Caesar's time used only what today we call upper-case letters.) So a call to cencrypt("Caesar", 1) should return (return not print) the string “DBFTBS” and a call...
Python Problem 1 Create a function, biggest_ip_sum, outside of the ServerClass class, that: 1. Takes two...
Python Problem 1 Create a function, biggest_ip_sum, outside of the ServerClass class, that: 1. Takes two ServerClass objects 2. Sums the octets of the IP together (example 127.0.0.1 = 127+0+0+1 = 128) 3. Returns the larger number Example: server_one = ServerClass("127.0.0.1") server_two = ServerClass("192.168.0.1") result = biggest_ip_sum(server_one, server_two) print(result) In the example above, result will be 361. _________________________________ Problem 1 Here is the code to start with class ServerClass: """ Server class for representing and manipulating servers. """ def __init__(self,...
#define number of stars numStars = 6 #define function - takes a number of stars and...
#define number of stars numStars = 6 #define function - takes a number of stars and prints an upside-down triangle def printTriangle(): printTriangle(numStars) Complete the function printTriangle(). the function is incomplete. print a triangle of stars. output is: ****** ***** **** *** ** * __________________________ #define list of numbers numbersList = [4, 12, 35, 13, 8, 13, 0, 2, 13, 13, 56] def removeUnlucky(): print("Unlucky: ",numbersList )removeUnlucky(numbersList )print("Lucky: ", numbersList) Complete the function removeUnlucky(). the program will not run because...
Step 1: Edit StringExplode.java Download the StringExplode.java file, and open it in jGrasp (or a text...
Step 1: Edit StringExplode.java Download the StringExplode.java file, and open it in jGrasp (or a text editor of your choice). This program will “explode” a String into an array of characters (char[]), and then print out the array. The String comes from the first command-line argument. Example output with the command-line argument foo is below: f o o --------------------------------------------------------------------- public class StringExplode { // TODO - write your code below this comment. // You will need to write a method...
1. Write a function named "countPositiveNegative" that accepts an array of integers, its size and return...
1. Write a function named "countPositiveNegative" that accepts an array of integers, its size and return the number of positive and negative in the array through the use of parameters. In addition, it also returns the number of 0s in the array as the return value. For example, array of {10, 20, -30, -40, 50, 0, 60} will return 4 for positives, 2 for negatives and 1 for 0's as the return value. 2. Write a function named "rotateRight" that...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT