Python Lab 01
Python Lab 01
1 Lab 1
1.1 Muhammad Haider
1.2 ITF-11126
2 1. Printing Output
[1]: print("Hello, World!")
Hello, World!
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
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.
"""