Cover page images (keyboard)

Conditionals Lab

James MacGlashan & Sue Evans

Hit the space bar for next slide







Overview

Objectives for today's lab:











Step 0: Setup

The first step is to create a lab4 folder in your cs201/labs directory and make a lab4.py file to start programming.

From your home directory :

cd 201/labs
mkdir lab4
cd lab4
emacs lab4.py &











Step 1 - What's a perfect number ?

Your task for lab 4 is to write a program that determines whether a number the user enters is a perfect number or not.

A perfect number is a positive integer that is equal to the sum of its divisors (excluding itself).
For example, the divisors of 6 are 1, 2 and 3. Since 6 = 1 + 2 + 3, 6 is a perfect number. The next three perfect numbers are 28, 496 and 8128.












Step 2 - How do I do that ?












Bonus Step - Eligibility

Use emacs to write bonus4.py that performs the following eligibility tests and prints out a report that states what things the user is eligible for and if they're not eligible for something, why not.

  1. For the Lab 4 bonus, you will prompt a user for information and tell them how eligible they are to smoke, drink alcohol, rent a car in Maryland, vote in Maryland, be a US senator, and be President of the United States
  2. To start you will prompt the user for the following information
    • Age
    • Length of time as a US citizen
    • Whether the user was born in the US
    • Length of time living in the US
    • How many times the user has been convicted a felony
  3. Based on the input information, the program should tell the user whether they are eligible for each of the criteria, and if not, why not.
    • To be able to smoke tobacco, the user must be >=18 years old.
    • To be able to drink alcohol, the user must be >=21 years old.
    • To be able to rent a car in Maryland, the user must be >=25 years old.
    • To be able to vote in Maryland, the user must be >= 18 years old, and have not been convicted of a felony more than once.
    • To be a US senator the user must be >= 30 years old, and have been a citizen for at least 9 years.
    • To be the President of the United States the user must be >=35 years old, was born in the US, and have lived in the US for at least 14 years.











Challenge Step - Security Clearance

Make a copy of your bonus4.py file called challenge4.py and modify the new file to include the eligibility for security clearance.