0% found this document useful (0 votes)
54 views

Lab 2

The document provides instructions for basic Python programming exercises. It discusses how to take user input using the input() function and display output using the print() function. It then provides 3 tasks - the first asks the user to input their last name and display a welcome message, the second asks for cylinder dimensions and calculates volume, and the third asks for a meal cost and calculates tax, tip and total bill.

Uploaded by

rashedbinkaram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Lab 2

The document provides instructions for basic Python programming exercises. It discusses how to take user input using the input() function and display output using the print() function. It then provides 3 tasks - the first asks the user to input their last name and display a welcome message, the second asks for cylinder dimensions and calculates volume, and the third asks for a meal cost and calculates tax, tip and total bill.

Uploaded by

rashedbinkaram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ABU DHABI POLYTECHNIC

Academic Support Department

Laboratory Manual No. 2

Python Programming
Basic Exercise

A.C. 2023-2024
A. Objectives:
1. Understand the fundamental concepts of programming using Python
2. Identify the steps in writing a Python program.
3. Create a simple program that reads input from the user in Python.
4. Create a simple program that displays an output in Python.

B. Materials Required:
1. Computer, Internet, Python IDE (https://replit.com/languages/python3)

C. Discussion:

How to read input from user in Python?

The input() function is used to gather data from the user.


Syntax:
variable_name = input([prompt])
Note: prompt is a string written inside the parenthesis that is printed on the screen.
Example:
person = input(“What is your name?”)
What is your name? Carrey
Note: Carrey is a value inputted by the user that is assigned to the variable person
Note: Any value inputted by the user is treated as “string” by default

How to print an output in Python?

The print() function allows the program to display text onto the console.

Example:

Program Code Output

print(‘This sentence is output to the screen’) This sentence is output to the screen

a=5

print(‘The value of a is ‘ , a) OR The value of a is 5

print(f’The value of a is {a}’)

*The input value by default has a String data type. int() function explicitly convert the data type
to an integer, and the float() function returns a floating point number.

Syntax: variable_name = int(input([prompt])) variable_name = float(input([prompt]))

Lab Manual No. 2| Page 2


Name: Rashed Abdulla Alblooshi. ID: ______________ Reserved Section
Grade:
Lab: _____________________________

Date: __________________________ CRN: ______________

Task 1
Write a python program that will read the user’s last name and assign its value to the variable lname.
1- Use f-string to display the output “Welcome to ICT 1011 Mr./Ms. <insert lname>”.

Task 1 Answer (Screenshot + program code)

lname=input("enter your last name? ")

print(f'welcome to ict1011 mr. / ms. {lname}')

Lab Manual No. 2| Page 3


Task 2
Write a python program that will read the diameter and height of a cylinder and it will output its
volume. Consider π = 3.14

Task 2 Answer (Screenshot + program code)

diameter = float(input("what is the diameter of the cylinder?"))


height = float(input("what is the height of the cylinder?"))
x= 3.14
volume = x*(diameter**2)*height/4
print("the volume of the cylinder is", volume)

Lab Manual No. 2| Page 4


Task 3
Write a python program that asks for the meal cost and calculates the tax, tip and the total bill.
The tax should be 10 percent of the meal cost.
The tip should be 20 percent of the total after adding the tax.
Display the tax amount, tip amount, and total bill with a message for each value.

Task 3 Answer (Screenshot + program code)

meal_cost = float(input("Enter the cost of the meal: "))

tax = 0.10 * meal_cost

total_with_tax = meal_cost + tax


print(f"Tax amount (10%): ${tax:.2f}")
tip = 0.20 * total_with_tax
print(f"Tip amount (20% of total with tax): ${tip:.2f}")
total_bill = total_with_tax + tip
print(f"Total bill: ${total_bill:.2f}")

Lab Manual No. 2| Page 5

You might also like