Lab Assignment 2, TCSS 142 solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

The objective of this assignment is to give you practice with formatting and Boolean expressions. The assignment consists of 4 exercises and covers the following:

 

  • formatting
  • Boolean expressions
  • truth tables
  • simple if statements
  • basic IO

 

 

ASSIGNMENT SUBMISSION

 

While the lab instructor walks around checking lecture exercises (pre-lab) on individual basis, start working with the assigned partner on exercise sets 2 and 3. Once you are done with a set, check with the one of the other pairs sitting next to you regarding their progress – help each other. Then, as a pair, present your solutions to the lab instructor. Each student is to have his/her version of the programs/answers and be capable of presenting them for the pair. The presenter will be chosen at random by the lab instructor. All the exercises other than the last set need to be shown to the lab instructor before leaving the lab for full credit. The last exercise set may be finished at home and shown in the beginning of the subsequent lab session. Use IDLE unless indicated otherwise.

 

  1. Lecture Exercises (20%)

Show the following exercises you were to create during the lecture:

  • py
  • py
  • py

 

  1. Formatting (25%)

Set up four variables: s1 and s2 to hold strings Mine and Yours, and i1 and i2 to hold integers 123 and 5. Then write appropriate print/format statements that use these variables and print the following to the console (the blue numbers on top indicate positioning):

12345678901234567890

Mine     Yours

123         5

Mine      Yours

123       5

 

 

 

 

 

 

Create two more variables: d1 = 123.4 and d2 = 3.1315926535

On a new line right-justify d1 and d2 within the field-width of 10 – what happens?

Finally, on a new line, left-justify the variable holding the string Mine and the variable holding the integer 123, each one within the field-width of 2 – what happens?

 

  1. Boolean Expressions (30%)

 

  1. Assuming int1 is 12, int2 is 9, and int3 is 8, write the result of each of the following Boolean expressions. In addition to running the code, write one sentence explaining the results (e.g. True and False => False) for each of the following:
  • int1 > int2 and int2 < int3
  • int1 < int3 or int3 > int2
  • int1 <= int2 – 6
  • int2 <= int1 + 5 or int3 >= int2 – 5
  • not(int1 < 30)
  • not(int2 == int1 and int3 == int1)
  • not(int1 > 5) and not (int2 < 17)

 

  1. Translate expression listed below into Python code. First create appropriate variables, assign values into them, and only then write each logical expression. Test your expressions and verify the results with the indicated values.
  • Temperature is between 55F and 68F, inclusive. Verify with temperature values 54F, 55F, 68F and 69F.
  • At least 25 credit hours are completed and GPA is higher than 3.5. Verify with (credit hour, GPA) = (55, 2.5), (15, 3.5), (25, 3.6), (23, 4).
  • Temperature is at most 70F and humidity is at least 70%. Verify with (Temperature, Humidity) = (55, 91), (70, 70), (45, 54), (0, 0)
  • Age is over 35 and less than 50 or income is at least $50,000. Verify with (age, income) = (35, $40,000), (40, $40,000), (50, $60,000), (25, $50,000)

 

  1. Truth tables and simple if (25%)

 

  1. In each of the following problems, you need to verify whether the pairs of logical expressions are equivalent using truth tables. This is a paper-based exercise; Show the written answer to your instructor.
  • Verify whether (i) not (A and B) and (ii) A or B  are equivalent.
  • Verify whether (i) A or B or C and (ii)  not A and not B and not C  are equivalent.

 

  1. (p. 115, ex. 1) 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, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday. The program should display an error message if the user enters a number that is outside the range 1 through 7.

 

 

 

—–  THE END —–