Question

In: Computer Science

Python Without running / testing the following code, predict what the following program prints on the...

Python

Without running / testing the following code, predict what the following program prints on the screen.

freeze = int(32)

boil = int(212)

freeze = 0

boil = 100

print(freeze, boil)

  • Write a program that asks the user for a number in the range of 1 through 7. The program should display the corresponding day of the week, where 1 = Monday, 2 = Tuesday and so forth. If the user types in a 6 then "Saturday" should be printed on the screen.
  • The program should display an error message if the user enters a number that is outside the range of 1 through 7.
  • Name the source code file
  • Test and run the program. Capture the output console and save it as an image file

Solutions

Expert Solution

1)

freeze = int(32)

boil = int(212)

freeze = 0

boil = 100

print(freeze, boil)

Ans: The output of the above program will be:

0 100

Explanation of output:

  • At the first line the the freeze is initialised with 32 (integer value)
  • Then the boil is initialised with 212 (again integer value)
  • At the third line however the value of freeze is reassigned as 0
  • Same way the boil s reassigned to 100
  • Then on the last line the program prints the values of freeze and boil separated by a space. These will be the most updated value of the variables which is 0 and 100
  • Hence the output becomes “0 100”


2)

Steps:

  1. Get input from user and save it’s int value
  2. Crosscheck the value with 1-7
  3. Print the corresponding week day in text
  4. If value not in range 1 and 7, print ‘invalid number’

Screenshot of code:

Sample Outputs:

Code to copy:

# prompt user to enter a number in range 1 to 7

# save int of input into variable n

n = int(input("Input A number between 1 and 7 (both including) : "))

# check if n is 1

if(n==1):

    # print Monday if 1

    print("Monday")

# check if n is 2

elif(n==2):

    # print Tuesday if 2

    print("Tuesday")

# check if n is 3

elif(n==3):

    # print Wednesday if 3

    print("Wednesday")

# check if n is 4

elif(n==4):

    # print Thursday if 4

    print("Thursday")

# check if n is 5

elif(n==5):

    # print Friday if 5

    print("Friday")

# check if n is 6

elif(n==6):

    # print Saturday if 6

    print("Saturday")

# check if n is 7

elif(n==7):

    # print monday if n is not in range 1-7

    print("Sunday")

# if n is not any of the numbers checked above

else:

    # print invalid numbers

    print("Invalid number for day of week")



Related Solutions

Without running the program, what happens if you run StackofStringsApp with “to be or not to...
Without running the program, what happens if you run StackofStringsApp with “to be or not to be that – is - - the question – whether tis nobler - - -“? Show how you came up with the answer (show your work). Write this on paper by hand. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- package stackofstringsapp; /****************************************************************************** * * % more tobe.txt * to be or not to - be - * * % java FixedCapacityStackOfStrings * to be or not to - be -...
Open selfmodifying.asm in MARS. Before running the code, predict: what will be the result in register...
Open selfmodifying.asm in MARS. Before running the code, predict: what will be the result in register $s0when this program is finished running? Now when you run the program, you will see an error: “Cannot read directly from text segment!”. To allow code to read and write the text segment, check Settings | “Self-modifying code”. Now click run again. a) Explain the result in register $s0when this program is finished running. In order to understand what is going on, we suggest......
use Python datetime module, strftime Write a program that processes the following textfile and prints the...
use Python datetime module, strftime Write a program that processes the following textfile and prints the report shown below. Textfile: Ask the user for the filename and BE SURE TO CHECK THAT IT EXISTS. The file will contain lines which each contain 2 strings (bookTitle and publicationDate) separated by a comma and a space. Note that the title of the book might contain spaces! Example of the textfile: Gone Girl, 5-24-2012 To Kill A Mockingbird, 7-11-1960 Harry Potter and the...
Create a python program that prints the series from 5 to 500.
Create a python program that prints the series from 5 to 500.
I have the following python code. I get the following message when running it using a...
I have the following python code. I get the following message when running it using a test script which I cannot send here: while textstring[iterator].isspace(): # loop until we get other than space character IndexError: string index out of range. Please find out why and correct the code. def createWords(textstrings): createdWords = [] # empty list for textstring in textstrings: # iterate through each string in trxtstrings iterator = 0 begin = iterator # new begin variable while (iterator <...
Python Explain Code #Python program class TreeNode:
Python Explain Code   #Python program class TreeNode:    def __init__(self, key):        self.key = key        self.left = None        self.right = Nonedef findMaxDifference(root, diff=float('-inf')):    if root is None:        return float('inf'), diff    leftVal, diff = findMaxDifference(root.left, diff)    rightVal, diff = findMaxDifference(root.right, diff)    currentDiff = root.key - min(leftVal, rightVal)    diff = max(diff, currentDiff)     return min(min(leftVal, rightVal), root.key), diff root = TreeNode(6)root.left = TreeNode(3)root.right = TreeNode(8)root.right.left = TreeNode(2)root.right.right = TreeNode(4)root.right.left.left = TreeNode(1)root.right.left.right = TreeNode(7)print(findMaxDifference(root)[1])
Write a program in PYTHON which: *Defines the following 5 functions: whoamI() This function prints out...
Write a program in PYTHON which: *Defines the following 5 functions: whoamI() This function prints out your name and PRINTS OUT any programming course you have taken prior to this course. isEven(number) This function accepts one parameter, a number, and PRINTS OUT a message telling if the numberer is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two. printEven(number) This function accepts one parameter, a number,...
Create and submit a Python program (in a module) that contains a main function that prints...
Create and submit a Python program (in a module) that contains a main function that prints 17 lines of the following text containing your name: Welcome to third week of classes at College, <your name here>! can someone please show me how to do this step by step? I'm just confused and keep getting errors in idle.
Write a Python program that reads in an amount in cents and prints the dollar amount...
Write a Python program that reads in an amount in cents and prints the dollar amount in that and the remaining value in cents. For example, if the amount reads in is 360 (cents), the program would print 3 dollars and 60 cents. if the amount read in is 75 (cents), the program would print 0 dollars and 75 cents.
Write a python code which prints triangle of stars using a loop ( for loop )...
Write a python code which prints triangle of stars using a loop ( for loop ) Remember what 5 * "*" does The number of lines of output should be determined by the user. For example, if the user enters 3, your output should be: * ** *** If the user enters 6, the output should be: * ** *** **** ***** ****** You do NOT need to check for valid input in this program. You may assume the user...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT