Lab 4: if-else Statements
Points Possible: 100
Due: Thursday, September 26th
In this lab, we will write programs using if-else statements.
Submission:
- 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.
- This is a group assignment, but you should each turn in your code individually.
- Groups will be assigned at the beginning of lab.
- Rules for groups work:
- Do not divide and conquer, i.e., do not assign each person an exercise to work on individually.
- Work together on each exercise and share responsibilities, each person should have a chance to write code.
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