TA Evaluation! (at Midterm)

Please make sure your TA places their name on the board.

After the TA has left the room, please click on the link below to take an ANONYMOUS survey.

TA Midterm Survey

The TA will reenter in 5 minutes and class will resume.

Please make sure your TA places their name on the board.

After the TA has left the room, please click on the link below to take an ANONYMOUS survey.

TA Midterm Survey

The TA will reenter in 5 minutes and class will resume.

James MacGlashan & Sue Evans

*Hit the space bar for next slide*

- Gain familiarity with working with conditionals
- Become familiar with using the mod operator
- Understand using conditionals to manage errors and special cases

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 &

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.

6 = 1+2+3

28 = 1+2+4+7+14

496 = 1+2+4+8+16+31+62+124+248

30 != 1+2+3+5+6+10+15

- Your task for lab4 is to write a program that takes a
**positive**integer from the user as input and prints whether it is a perfect number or not. - If the user enters a negative number, 0, or a floating point number, you
should not continue and inform the user the number needs to be a
positive integer. (Use the type function to help) You can end your program by making a call to
sys.exit().
**You'll need to import sys to be able to use sys.exit()** - You should loop through all integers less than the input integer, and add them together if they are divisors of the input integer.
- To loop through all integers less than the integer
**<number>**you use the following format: - The modulus operator in python is the percent symbol '%'.
- The modulus of two numbers
`A % B`is the**remainder**after dividing A by B.

for i in range(1, number): #do something with i

>>> 5 % 1 0 >>> 5 % 2 1 >>> 5 % 3 2 >>> 5 % 4 1

Use emacs to write bonus4.py that prompts the user to input x-y coordinates of a point in a Cartesian plane.

- For the Lab 4 bonus, you will prompt a user for two values (x and y) to determine where that point lies either in a quadrant, origin, or on an axis. Use the chart above.
- To start you will prompt the user for the following information
- x (x coordinate)
- y (y coordinate)

- Based on the input information, the program should tell the user
whether the point is located in:
- the origin
- x axis
- y axis
- Quadrant 1
- Quadrant 2
- Quadrant 3
- Quadrant 4