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

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...
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.
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?
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)
1.    Given the Utility function U(X,Y) = X.5 + Y.5 a.    Write mathematical expressions for marginal utility of...
1.    Given the Utility function U(X,Y) = X.5 + Y.5 a.    Write mathematical expressions for marginal utility of x and marginal utility of y b.    Does the consumer the assumption of non-satiation (more is better) desire more of x and y? c.    If the quantity of Y is held constant, does the marginal utility of x increase, remain constant or diminish as x increases? Prove your answer d.    Derive an expression for the marginal rate of substitution of x for y. e.    If Price of X...
JAVA - Programming Exercise 10-5. The developers of a free online game named Sugar Smash have...
JAVA - Programming Exercise 10-5. The developers of a free online game named Sugar Smash have asked you to develop a class named SugarSmashPlayer that holds data about a single player. The class contains the following fields: idNumber - the player’s ID number (of type int) name - the player's screen name (of type String) scores - an array of integers that stores the highest score achieved in each of 10 game levels Include get and set methods for each...
1. Write a function named “Number” that reads in a list of numbers until the user...
1. Write a function named “Number” that reads in a list of numbers until the user enters 0. It will return true if the user has entered more even numbers than odd numbers; otherwise it returns false. 2. Write a code segment to sort an array of students in ascending order of their IDs. Assume the array has been filled with names and assume the following declaration: struct Student { string name; int ID; } Student roster[30]; // Code to...
Write a C program that evaluates the factorials from 1 to 5. Print results in a...
Write a C program that evaluates the factorials from 1 to 5. Print results in a tabular format.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT