Week 1
Week 1
1 i). Use a web browser to go to the Python website http://python.org. This page contains information
about Python and links to Python-related pages, and it gives you the ability to search the Python
documentation.
Open a Web Browser: Use any web browser you prefer (e.g., Chrome, Firefox, Safari).
Go to the Python Website: Enter the URL https://www.python.org into your browser's address bar and
press Enter. This will take you to the homepage of the official Python website.
Explore the Website: The Python website is designed to be user-friendly and contains a wealth of
information about Python, including recent news, upcoming events, and resources for learning
Python.
Access Python Documentation: On the top navigation bar, there's a link labeled "Docs." Hovering over
this link will reveal a drop-down menu that provides direct access to Python's documentation for
various versions. Click on the version of the documentation you wish to view.
Use the Search Feature: If you're looking for specific information within the Python documentation,
you can use the search bar typically located at the top of the documentation page. Enter your query
into the search bar and press Enter to search the Python documentation.
1 ii). Start the Python interpreter and type help() to start the online help utility.
To start the Python interpreter and access the online help utility, you'll need to follow these steps:
On Windows, you can search for "cmd" or "Command Prompt" in the Start menu.
Access the Help Utility: Once the Python interpreter starts (you'll see the >>> prompt), type help()
and press Enter. This command launches Python's built-in help system.
>>>help()
After typing help(), you'll enter the interactive help utility. Here, you can type the name of any Python
module, keyword, or topic to get more information. For example, you can type keywords to see a list
Here's a quick example of starting the Python interpreter and accessing the help utility:
quit
This interactive help utility is a powerful resource for learning and exploring Python's extensive
python
or
python3
Perform Calculations: Once the Python interpreter starts and you see the >>> prompt, you can
start performing calculations. The interpreter can handle basic arithmetic (addition, subtraction,
To exit the Python interpreter, you can type exit() or press Ctrl+D (on Unix-based systems) or Ctrl+Z
exit()
3 i). Write a program to calculate compound interest when principal, rate and number of periods are
given.
To calculate compound interest in Python when the principal amount, interest rate, and number of
return interest
This program defines a function calculate_compound_interest that takes the principal amount, annual
interest rate, and number of periods as input and calculates the compound interest using the provided
formula. Then, it prompts the user to input the principal, rate, and periods, calculates the compound
3 ii). Given coordinates (x1, y1), (x2, y2) find the distance between two point.
To calculate the distance between two points given their coordinates ((x1, y1)) and ((x2, y2)), you can
use the distance formula derived from the Pythagorean theorem. The formula to calculate the distance
import math
return distance
input and calculates the distance using the distance formula. Then, it prompts the user to input the
4. Read name, address, email and phone number of a person through keyboard and print the details.
To read a person's name, address, email, and phone number from the keyboard and print these
print("\nPerson Details:")
print("Name:", name)
print("Address:", address)
print("Email:", email)
This program uses the input function to prompt the user for their name, address, email, and
phone number. After the details are entered, it prints them out.