0% found this document useful (0 votes)
13 views3 pages

Python Lab 01

This document outlines basic programming concepts using Python, including printing output, taking user input, performing arithmetic operations, and using conditional statements. It also covers looping structures, list operations, function definitions, and comments. Each section includes example code snippets and their outputs.

Uploaded by

Muhammad Haider
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)
13 views3 pages

Python Lab 01

This document outlines basic programming concepts using Python, including printing output, taking user input, performing arithmetic operations, and using conditional statements. It also covers looping structures, list operations, function definitions, and comments. Each section includes example code snippets and their outputs.

Uploaded by

Muhammad Haider
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/ 3

rada2fxl5

March 28, 2025

1 Lab 1
1.1 Muhammad Haider
1.2 ITF-11126

2 1. Printing Output
[1]: print("Hello, World!")

Hello, World!

3 2. Taking User Input


[2]: name = input("Enter your name: ")
print("Hello, " + name)

Enter your name: 10


Hello, 10

4 3. Simple Arithmetic Operations


[3]: a, b = 5, 3
print("Sum:", a + b)
print("Product:", a * b)

Sum: 8
Product: 15

5 4. Conditional Statement
[4]: num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")

1
Enter a number: 13
Odd

6 5. Looping (for & while)


[7]: for i in range(1, 6):
print(i)

count = 3
while count > 0:
print("Looping...")
count -= 1

1
2
3
4
5
Looping…
Looping…
Looping…

7 6. List Operations
[8]: numbers = [1, 2, 3, 4, 5]
print("List:", numbers)
print("First Element:", numbers[0])

List: [1, 2, 3, 4, 5]
First Element: 1

8 7. Function Definition
[10]: def greet(name):
return f"Hello, {name}!"

print(greet("Alice"))

Hello, Alice!

2
9 8. Comment Example
[12]: # This is a single-line comment explaining the code
"""
This is a multi-line comment
explaining the purpose of the code.
"""

[12]: '\nThis is a multi-line comment \nexplaining the purpose of the code.\n'

You might also like