Question

In: Computer Science

Exercise 1. Write a function named printBox to print a 5 x 10 box of asterisks...

Exercise 1. Write a function named printBox to print a 5 x 10 box of asterisks using nested loops. When printBox() is called your function should display the pattern shown below.

Write a function named printBox to print a 5 x 10 box of asterisks
using nested loops. When printBox() is called your function should
display the following information.

**********
**********
**********
**********
**********

"""

# place the code for the printBox function here


printBox( numRows, numCols )

Exercise 2. Write a function to print a m x n box of asterisks using nested loops where m represents the number of rows and n represents the number of columns.

Write a function to print a m x n box of asterisks using nested loops where
m represents the number of rows and n represent the number of columns.

If the user enters 3 for the number of rows and 4 for the number of columns,
when printBox( numRows, numCols ) is called your function should display
the following:

****
****
****

"""

# place the code for the printBox function here


numRows = int( input( 'Enter the number of rows: ') )
numCols = int( input( 'Enter the number of columns: ') )
printBox( numRows, numCols )

. For example, if the user enters 3 for the number of rows and 4 for the number of columns when printBox( numRows, numCols ) is called your function should display the following:

****

****

****

Exercise 3. Complete the convertTemperture function in exercise3.py by replacing the pass statement with code to compute the temperature conversion and return the converted Celsius value when convertTemperature( tempInF ) is called. Recall you wrote an expression to perform temperature conversion in laboratory assignment 2. The mathematical formula for temperature conversion is: ?? = 5 9 ∙ (?? − 32) where F is the temperature in Fahrenheit and C is the temperature in Celsius. Use floating-point values in your calculation.  

def convertTemperature( fahrenheit ):
pass

tempInF = float( input( "Enter a temperature in Fahrenheit: "))
tempInC = convertTemperature( tempInF )

print( f'{tempInF:.1f} Fahrenheit is {tempInC:.1f} in Celsius' )

Exercise 4. Write a function that prompts the user to enter x and y values of a point in a 2-D coordinate system. Your function should return the two values as the values of the function. This source code calls your function to get values for x and y, and then display the coordinate value. After you add the function definition for getCoordinate.

def getCoordinate():
pass


# these lines call your function to get values of the
# coordinates and displays the result
x, y = getCoordinate()
print ( f'You entered the coordinate <{x},{y}>' )

Solutions

Expert Solution

Exercise 1:

def printBox():
        for i in range(5):
                for j in range(10):
                        print("*", end =" ") 
                print()

printBox()

Exercise 2:

def printBox(numRows,numColumns):
        for i in range(numRows):
                for j in range(numColumns):
                        print("*", end ="") 
                print()

numRows = int( input( 'Enter the number of rows: ') )
numCols = int( input( 'Enter the number of columns: ') )
printBox( numRows, numCols )

Output:

Exercise 3:

def convertTemperature( fahrenheit ):
        celsius = (fahrenheit - 32) * 5.0/9.0
        return celsius

tempInF = float( input( "Enter a temperature in Fahrenheit: "))
tempInC = convertTemperature( tempInF )

print( f'{tempInF:.1f} Fahrenheit is {tempInC:.1f} in Celsius' )

Output:

Exercise 4:

def getCoordinate():
        x = float( input( "Enter x coordinate: "))
        y = float( input( "Enter y coordinate: "))
        return x,y


x, y = getCoordinate()
print ( f'You entered the coordinate <{x},{y}>' )

Output :


Related Solutions

Write a Java program to print the pattern of asterisks shown below. For i=1 * For...
Write a Java program to print the pattern of asterisks shown below. For i=1 * For i=2 * * * For i=3 * ** * * * For i=n * * * * * * … … … * * * * * * ……… n
X=5,Y=7,Z=10 A. if(X<Y): print "LESS" else: print "OTHER" B. if (x == 1): print "ONE" elif...
X=5,Y=7,Z=10 A. if(X<Y): print "LESS" else: print "OTHER" B. if (x == 1): print "ONE" elif (x == 2): print "TWO" elif (x == 3): print "THREE" elif (x == 4): print "FOUR" elif (x == 5): print "FIVE" elif (x == 6): print "SIX" else: print "OTHER" C. if (X<Z): print X X = X + 1 D. while (X<Z): print X X = X + 1 Q11. What is the final value of X in D Q12. Is...
Write a c++ function named multi_table to print out multiplication table for a given number of...
Write a c++ function named multi_table to print out multiplication table for a given number of rows and columns. Your program should print a header row and a header column to represent each row and column number. For example your function call multi_table(4, 4) would print below to the command line: 1 | 1 2 3 4 _________ 2 | 2 4 6 8 3 | 3 6 9 12 4 | 4 8 12 16 Test your function in...
Using C++ code, write a program named q5.cpp to print the minimum of the sums x...
Using C++ code, write a program named q5.cpp to print the minimum of the sums x + y^3 and x^3 + y, where x and y are input by a user via the keyboard.
IDS 201 Lab Exercise 5 Within a class named LX5, write methods as follows: 1. a...
IDS 201 Lab Exercise 5 Within a class named LX5, write methods as follows: 1. a method named valueCheck that accepts a parameter int named value and, using a switch statement, displays text output as follows: if value is 4 or greater: "LOTS" if value equals 3: "three" if value equals 2: "two" if value equals 1: "one" if value equals 0: "zero" if value is negative: "NEGATIVE" 2. a method named textMatch that accepts two parameter String objects named...
write a programme named question5a.cpp that calculate and print pay slip
write a programme named question5a.cpp that calculate and print pay slip
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The...
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The function will have one int 1D array n and one int size as parameters. The function will display all the values of n on one line. Function #2 Write the function AverageEvenOdd. The function will have one int 1D array n and one int size as parameters. The size of the array is given by the parameter int size. Therefore, the function should work...
1. write a function to represent the volume of the box given that the sum of...
1. write a function to represent the volume of the box given that the sum of the height and perimeter of the base is equal to 240 inches. 2. what dimensions (lenght width height) of such a box will give the maximum volume? 3. what is the maximum volume?
Write the following easy Python functions: 1) Write the function named roundDollars(). The function has one...
Write the following easy Python functions: 1) Write the function named roundDollars(). The function has one input, a String named amountStr which consists of a dollar-formatted amount, such as "$ 1,256.86". The returned value is an int representing the number of rounded "dollars" in the amount, (1257 in the sample shown here). You will need to scrub, format and parse the input, then use arithmetic to determine how many rounded dollars the amount contains. roundDollars("$ 1,256.86") → 1257 roundDollars("$ 0.42")...
Find the derivative of the function y= (x + 5)(x + 1) / (x - 5)(x...
Find the derivative of the function y= (x + 5)(x + 1) / (x - 5)(x - 1)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT