Lab Assignment 3, 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 the basic programming concepts, basic Python syntax, and tools. The assignment consists of 4 exercises and covers the following:

 

  • if and if-else statements
  • nested ifs
  • testing ifs
  • basic for loops

 

 

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 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 or IfExample2.py
  • py
  • py

 

  1. Nested ifs and testing (30%)

Download FactorExample.py and run it. The program runs correctly but includes some unnecessary statements. First look at the code and run the program with different gpa values to see which message corresponds to which gpa value. Construct an appropriate test plan for the code.

Then, restructure the code to eliminate unnecessary statements while retaining the same behavior. Make sure that you take care of the real number representation issue and never compare a real number for exact equality.

 

Test Case Reason for the test Expected output
4.0 Testing the valedictorian path I made the dean’s list for this class!

I’m valedictorian for this class! Woo hoo!

Credits earned:  5

     
     

 

 

  1. for loops (30%)

Write one program that contains solutions to the following for loop exercises:

  1. it adds up the first n terms of the arithmetic sequence: { 1, 4, 7, 10, 13, … } using a for loop, and then prints the resulting total – the user enters the number of terms to be added up
  2. it adds up the first n terms of the geometric sequence that halves each time: { 1/2, 1/4, 1/8, 1/16, … } using a for loop, and then prints the resulting total – the user enters the number of terms to be added up
  3. it calculates factorial of number n using a loop, and then prints the resulting number – the user enters a nonnegative integer n, e.g. if a user enters 7, your program prints 5040 since  7! = 7 x 6 x 5 x 4 x 3 x 2 x 1

 

  1. Nested ifs and for (20%)
  2. Write a program that asks the user to enter a pair of real numbers x and y and prints the quadrant for that point. If the point lies at the origin, print ‘origin.’ If the falls on either axis, print which axis it lies on.

 

Example: (-4.2, 17.3) prints quadrant 2

(0, 12) prints y-axis

 

  1. Write a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, four pennies the third day, eight pennies the fourth day, and continues to double each day. The program should ask the user for the number of days.

Display a table showing what the salary was for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies.

 

 

 

—–  THE END —–