Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CodeLab CodeLab #1 ----- Language: Python ----- Question: Two variables, num and cost have been assigned values. Write a single statement that outputs num and

CodeLab

CodeLab #1

----- Language: Python

-----

Question: Two variables, num and cost have been assigned values. Write a single statement that outputs num and cost to standard output. Print both values (num first, then cost), separated by a space on a single line that is terminated with a newline character. Do not output any thing else.

These are wrong: 1. print(num,' ',cost)

2. print(num,' ',cost, ' ')

=====

Question: Write a single statement that will print the message "first is" followed by the value of first, and then a space, followed by "second = ", followed by the value of second. Print everything on one line and go to a new line after printing. Assume that the variables have already been given values.

Instructor Notes:

There should be a space between the string "first is" and the value of the first variable.

=====

Question: Write some code that reads in a name and an age into the variables name and age. It then prints the message "The age of NAME is AGE" on a line by itself, where NAME and AGE represent the values read into the variables name and age respectively. For example, if your code read in "Rohit" and 70 then it would print out "The age of Rohit is 70" on a line by itself. There should NOT be a period in the output.

Instructor Notes:

The age needs to be an integer, not a string.

=====

Question: Write some code that reads a value representing a name into the variable name then prints the message "Greetings, NAME!!!" on a line by itself where NAME is replaced the value that was read into name. For example, if your code read in "Hassan" it would print out "Greetings, Hassan!!!" on a line by itself.

Instructor Notes:

If you see a \ (backslash) in front of the exclamation marks, it shouldn't be there; some browsers seem to erroneously display it.

=====

Question: Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Assuming the item is paid for with a minimum amount of change and just single dollars, write an expression for the amount of change (in cents) that would have to be paid.

=====

Question: Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents" on a line by itself. So, if the value of price was 4321, your code would print "43 dollars and 21 cents". If the value was 501 it would print "5 dollars and 1 cents". If the value was 99 your code would print "0 dollars and 99 cents".

=====

Question: The dimensions (width and length) of room1 have been read into two variables: width1 and length1. The dimensions of room2 have been read into two other variables: width2 and length2. Write a single expression whose value is the total area of the two rooms.

=====

Question: In mathematics, the Nth harmonic number is defined to be 1 + 1/2 + 1/3 + 1/4 + ... + 1/N. So, the first harmonic number is 1, the second is 1.5, the third is 1.83333... and so on. Assume that n is an integer variable whose value is some positive integer N. Assume also that hn is a variable whose value is the Nth harmonic number. Write an expression whose value is the (N+1)th harmonic number.

=====

Question: Given two variables, already defined, best_value and second_best_value, write a statement that swaps their associated values.

=====

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions