Prints "Hello World" to the console.
print("Hello World")
Assign values to variables and print them.
x = 10
y = 5
print(x + y)
Basic if-else condition example.
age = 18
if age >= 18:
print("Adult")
else:
print("Minor")
Loop through numbers 1 to 5.
for i in range(1, 6):
print(i)
Loop until a condition is false.
count = 0
while count < 5:
print(count)
count += 1
Define and call a simple function.
def greet(name):
print(f"Hello {name}")
greet("Alice")
Create a list and print each element.
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
Create a dictionary and access elements.
person = {"name": "Alice", "age": 25}
print(person["name"])
Import and use the math module.
import math
print(math.sqrt(16))
Generate a random number between 1 and 10.
import random
print(random.randint(1, 10))