Question: 1. Write a trace for the following program: def triplelt( myNumber ): returnValue = myNumber * 3 myNumber = myNumber + 1 return returnValue myNumber

1. Write a trace for the following program:

def triplelt( myNumber ):

returnValue = myNumber * 3

myNumber = myNumber + 1

return returnValue

myNumber = 3.3

newNumber = triplelt( myNumber )

2: Write a trace for the following program:

def formatNumber(number):

if number % 2 = = 1

formattedNumber = "--" + str( number ) + "-"

else:

formattedNumber = "-" + str(number ) + "-"

return formattedNumber

c = 5

p = 3

output = ""

while c < 20;

temp = c + p

p = c

c = temp

output = output + format Number(c)

print( output)

3: If x = 6, what is the value of result in result = x >=3*2?

4: For any Boolean expressions a and b, is the following equation always valid? not( a and b ) = not( a ) and not( b ) Yes or no?

5: For any Boolean expressions a and b, is the following equation always valid? not( a or b ) = not(a) or not(b)

6: Write a python modular called miles2kilometers that will accept one float parameter, distance in miles, and returns a float value represents the distance in kilometers. Note: there are 0.6 miles in 1 kilometer. For example miles2kilometers( 10 ) will turn a value of 6. Write a small main module that asks the user for input, calls the function, and displays the output from the function call.

7: Write a python IF statement that implements the following logic. Have the user input an integer value and save it to the variable owing. Set the variable OK to True if the boolean variable isPaid contains True and the variable owing is between 100 and 200 inclusive. Set OK to False if isPaid contains True and the variable owing is less than or equal to 0. Set OK to False otherwise. Print a message that says whether OK is true or false.

8: Design using pseudocode and implement a solution to the problem in Python. Create a test and show a trace of your design.

Create a module called is_prime that accepts a single integer. You may assume that all integers that will be entered will be greater than 1. The is_prime module should return true if the number entered is 1 or if the number can only be divided without a remainder by itself and 1.

Create a main routine that will ask the user to enter a positive integer greater than 500. You may assume the user enters a valid integer. Print out all of the prime numbers that are between 1 and the user's input inclusive.

Results may not rely on a literal variable containing prime numbers, in any format, and the prime numbers all be calculated by some method.

9: Write a python IF statement that implements the following logic.

A user enters a number that is saved in an integer variable called "uni". If "uni" is negative, double it. If "uni" is positive, halve it. If "uni" is exactly 0 add 3 to it.

Display the result in a sentence like "Your number was positive, so I halved it, now it is" and the result. For example: "Your number was positive, so I halved it, now it is 3.5" is the user entered 7.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!