Python Basics
Output
print("Hello, World!")
print("My name is", "Alice")
Variables
name = "Alice"
age = 25
height = 5.7
is_student = True
Input
name = input("What is your name? ")
age = int(input("How old are you? ")) # convert to integer
String Operations
first = "Hello"
second = "World"
combined = first + " " + second # "Hello World"
length = len(combined) # 11
upper = combined.upper() # "HELLO WORLD"Example
# Python Basics Demo
name = "Amina"
age = 16
school = "Federal Government College"
print(f"Name: {name}")
print(f"Age: {age}")
print(f"School: {school}")
# Lists
subjects = ["Math", "English", "Science", "Civic Ed"]
print("
Subjects:")
for i, sub in enumerate(subjects, 1):
print(f" {i}. {sub}")
# Function
def calculate_average(scores):
return sum(scores) / len(scores)
quiz_scores = [85, 92, 78, 95, 88]
avg = calculate_average(quiz_scores)
print(f"
Average score: {avg:.1f}")
Exercises
Exercise 1. Greet Using an f-string
Easy
Create a variable name with the value "Ada" and print exactly: Hello, Ada!
Use an f-string: print(f"Hello, {name}!")
Use an f-string: print(f"Hello, {name}!")
# your code here
Expected Output
Hello, Ada!