Lab 4: if-else Statements | CMSC 105 Elementary Programming - Fall 2024

Lab 4: if-else Statements

Points Possible: 100

Due: Thursday, September 26th

In this lab, we will write programs using if-else statements.

Submission:

  1. Submit a Python file for each of the programs.

Pair programming

Pair programming is a software development technique in which two programmers work together at one computer. One, the driver, writes code while the other, the navigator, reviews each line of code as it is typed in. The two programmers switch roles frequently.

Program 1: Oldest and Youngest

Draw a flowchart of the program design take a picture and save it as flow1.png and attach it to the Blackboard lab assignment.

Write a program that reads ages of 3 different users and determine the oldest and youngest among them. Display the results.

Save the program is ages.py and attach it to the Blackboard lab assignment.

Complete a tracing table of the program above and take a picture and save it as trace1.png and attach it to the Blackboard lab assignment.

Grading Rubric for the program:
(Comments: 5, Input and output: 5, Computation: 10, flowchart and tracing: 10)
Total: 30 points

Program 2: Find future days

Draw a flowchart of the program design take a picture and save it as flow2.png and attach it to the Blackboard lab assignment.

Write a program that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1, …, and Saturday is 6). Also, prompt the user to enter the number of days after today for a future day and display the future day of the week.

Here is a sample run:

Enter today’s day: 1
Enter the number of days elapsed since today: 3
Today is Monday and the future day is Thursday

Hint: You can see the example from Lecture 2 slides for future day calculation.

Save the program is days.py and attach it to the Blackboard lab assignment.

Complete a tracing table of the program above and take a picture and save it as trace2.png and attach it to the Blackboard lab assignment.

Grading Rubric for the program:
(Comments: 5, Input and output: 5, Computation: 20, flowchart and tracing: 10)
Total: 40 points

Program 3: Divisible By

Draw a flowchart of the program design take a picture and save it as flow3.png and attach it to the Blackboard lab assignment.

Write a program that reads a number from the user and checks the following:
a. Number is divisible by 2 and 3
b. Number is divisible by 2 or 3
c. Number is divisible by 2 or 3 but not both

The program will display the results.

Note: There will be 3 different if statements as these are independent conditions.

Save the program is divisible.py and attach it to the Blackboard lab assignment.

Complete a tracing table of the program above and take a picture and save it as trace3.png and attach it to the Blackboard lab assignment.

Grading Rubric for the program:
(Comments: 5, Input and output: 5, Computation: 10, flowchart and tracing: 10)
Total: 30 points