Input / Output
# Input and Output Program
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Name:", name)
print("Age:", age)
Data Types
# Data Types Program
a = 10 # int
b = 3.14 # float
c = "Python" # string
d = True # boolean
print(type(a))
print(type(b))
print(type(c))
print(type(d))
Operators
# Operators Program
x = 10
y = 3
print(x + y)
print(x - y)
print(x * y)
print(x / y)
print(x % y)
Conditional Statements
# Conditional Statements Program
num = int(input("Enter a number: "))
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
Loops
# Loops Program
for i in range(1, 6):
print(i)
i = 1
while i <= 5:
print(i)
i += 1
Strings
# Strings Program
text = "Hello Python"
print([Link]())
print([Link]())
print(text[0:5])
print(len(text))
Lists
# Lists Program
numbers = [1, 2, 3, 4, 5]
[Link](6)
[Link](3)
for n in numbers:
print(n)
Tuples
# Tuples Program
t = (10, 20, 30)
print(t[0])
print(len(t))
Dictionaries
# Dictionaries Program
student = {
"name": "Alice",
"age": 20,
"course": "CS"
}
print(student["name"])
print([Link]())
print([Link]())
Functions
# Functions Program
def add(a, b):
return a + b
result = add(5, 3)
print("Sum:", result)
File Handling
# File Handling Program
file = open("[Link]", "w")
[Link]("Hello File")
[Link]()
file = open("[Link]", "r")
print([Link]())
[Link]()
Modules
# Modules Program
import math
print([Link](16))
print([Link](5))