Lab 2 Manual(1)
Lab 2 Manual(1)
Lab 2 Manual(1)
Lab Requirements
PyCharm (IDE).
Solution
2
Phase 2: Implementation Phase:
1. Open PyCharm.
2. Then, click on “ New Project”.
3. Then, name it “Lab 2”.
4. Then, the new project is created and opened. After that, you have to create a new
Python file inside the project to write the code on it.
5. Select the project name on the left menu, right click on it and select “New” → “Python
File”.
6. Then, name the new file “activity_1”, and click on “Python file”.
7. Now, the new file is created and opened. Write the code in it:
activity_1.py
1 '''
2 ( (9.5 * 4.5) - (2.5 * 3) ) Numerator
3 / Divided by
4 (45.5 - 3.5) Denominator
5 '''
6 print( ((9.5 * 4.5) - (2.5 * 3)) / (45.5 - 3.5) )
8. To run the file, right click on any area of the editor and click on (Run 'activity_1'), which
is the name of the file.
3
9. After that, PyCharm is going to run the file using the Python interpreter, and then display
the output of the file to you.
4
1 1 1 1 1 1 1
and 𝜋 = 4 × (1 − + − + − + − )
3 5 7 9 11 13 15
2.9760461760461765
3.017071817071818
Solution
5
3. Write the following code in the file:
activity_2.py
1 # Displays the result of the first equation
2 print(4 * (1-(1/3)+(1/5)-(1/7)+(1/9)-(1/11)))
3
4 # Displays the result of the second equation
5 print(4 * (1-(1/3)+(1/5)-(1/7)+(1/9)-(1/11)+(1/13)-(1/15)))
45
Write a program that displays the area and perimeter of a circle that has a radius of 5.5
using the following formulas (Note: π = 3.14159):
𝑎𝑟𝑒𝑎 = 𝑟𝑎𝑑𝑖𝑢𝑠 × 𝑟𝑎𝑑𝑖𝑢𝑠 × 𝜋
𝑝𝑒𝑟𝑖𝑚𝑒𝑡𝑒𝑟 = 2 × 𝑟𝑎𝑑𝑖𝑢𝑠 × 𝜋
7
95.0330975
34.55749
8
Extra Exercises (Homework)