ITC Lab 09
ITC Lab 09
Lab 09
Topic Getting Started with Python
Tool Installation
Basic Python Syntax
Objective Input/Output
Datatypes and Variables
Conditional Statements
Installation Guide:
Python is free. To download Python to your
On your computer, you must first visit the official website at http://python.org
Download and then custom install the Python setup check all the boxes while
installing.
Write “cmd” in the start then open the command prompt, and check if Python
is installed.
Then write the command python --version.
Once you have Python successfully downloaded, there are several integrated
development environment (IDE) for Python that you can write and run your
Python programs. We’ll use VS Code.
An IDE allows you to create, edit, run, troubleshoot, save, and open your code
all in the same easy-to-use program.
To download the setup use the link: Download Visual Studio Code - Mac, Linux,
Windows
After installing the IDE. Launch the VS Code
Download extension for VS code
Click on extension button and search Python in search bar. Install the first
suggestion that appears for python:
After installation of python extension, go to the explorer option and click on
open folder
Create a folder in any drive with any name you like and select that folder in the
explorer
Click on new file and create a file having any name with (.py) extension. Double
click or press enter to open the editor.
2. num = 10
print(“Number: ”,num)
Input: input()
Examples:
1. var = input() -> by default string type
2. var = int(input()) -> convert to int to use the variable
for numbers
3. print(“Enter Number: ”)
num=input()
print(“Number: ”,num)
4. num=input(“Enter Number: ”)
print(“Number: ”,num)
percentage=(marks/50)*100
print("Marks: ",marks,
"\nPercentage: ",percentage,"%")
Output:
Enter Name: ahmad
Enter Age: 20
Enter Email: [email protected]
Enter Degree: bsse
Enter Contact: 0333-1234567
Enter Marks out of 50: 42
Name: ahmad
Age: 20
Email: [email protected]
Contact: 0333-1234567
Degree: bsse
Marks: 42
Percentage: 84.0 %
Conditional Statements:
1. if/else
2. if/elif/else
print("Grade: ",grade)
Output:
Enter Name: ali
Enter Marks out of 100: 76
Grade: B
print("Grade: ",grade)
Output:
Enter Name: ali
Enter Marks out of 100: 76
Grade: B
Lab task
Task 1: Even or Odd
Write a Python program to check if a number is even or odd.
Write a Python program for designing a system for an event ticket booth. The system
should:
1. Ask the user to input the number of adults and children attending the event.
2. The price per adult is $20, and the price per child is $10.
3. Calculate and display the total cost of the tickets.
Input/Output Steps:
A teacher wants to calculate the average marks for a class. The system should:
Input/Output Steps:
1. Input: Number of students and each student’s grade.
2. Output: Average marks.
You are building a currency converter for a travel website. The system should:
1. Ask the user to input the amount of money they want to convert.
2. Based on the exchange rate, calculate the converted amount.
3. Display the converted amount.
Input/Output Steps:
If the candidate is female, unmarried, and aged between 18 and 35, she is suitable for
both cities and towns; otherwise, she will only work in big cities.
If the candidate is male, unmarried, and between 18 and 42 years old, then he is
suitable for both cities and towns.
if the candidate is male and married and their age is between 18 to 42 then he is
suitable for big cities only.
And any other input of age should print "Candidate is not preferred for the job".
You are designing a water heater controller that adjusts based on water temperature. The system
should:
You are building a ride-share app that adjusts the price of a ride based on traffic conditions
and time of day. The system should:
1. If it’s rush hour (7-9 AM or 5-7 PM) and heavy traffic, increase the base fare by 50%.
2. If it’s rush hour but traffic is light, increase the base fare by 20%.
3. Use the normal base fare if it’s not rush hour.
Home Task
Task 10: Geometry Calculator
Write a Python program to create a geometry calculator:
Display Menu:
Calculate the Area of a Circle
Calculate the Area of a Rectangle
Calculate the Area of a Triangle
Quit
Enter your choice (1-4):
If the user enters 1, the program should ask for the radius of the circle and then display its
area. Use the following formula:
area = πr2
Use 3.14159 for π and the radius of the circle for r. If the user enters 2, the program should
ask for the length and width of the rectangle and then display the rectangle’s area. Use the
following formula:
area = length * width
If the user enters 3 the program should ask for the length of the triangle’s base and its
height, and then display its area. Use the following formula:
area = base * height * 0.5
If the user enters 4, the program should end.
Input Validation: Display an error message if the user enters a number outside the range of 1
through 4 when selecting an item from the menu. Do not accept negative values for the
circle’s radius, the rectangle’s length or width, or the triangle’s base or height.