Python as a calculator
Python can evaluate expressions with operators like +, -, *, and /. Parentheses control order, and numbers can be integers or decimal values.
PyLume
Start with the core ideas from the Python documentation: values, variables, text, lists, decisions, loops, functions, and data structures. When you are ready, open the explainer and paste your code.
Go to Code ExplainerPython can evaluate expressions with operators like +, -, *, and /. Parentheses control order, and numbers can be integers or decimal values.
A variable stores a value with a name. After assignment, you can reuse that name in later calculations, function calls, or output.
Text values are strings. They can use single or double quotes, can be printed with print(), and can be combined, sliced, or repeated.
Lists keep multiple values in order. You can access items by position, add or remove items, and loop through the list to process each value.
if, elif, and else let a program choose what to do. This is how code reacts to different inputs or states.
for loops repeat work over a sequence. while loops repeat while a condition remains true.
A function gives a reusable name to a block of code. Inputs go in as parameters, and a result can come back with return.
Dictionaries store key-value pairs. Sets store unique values. Both are useful when you need faster lookup or clean grouping.
Read these small programs first, then open the explainer page and paste one to see the step-by-step explanation.
name = "Mukilan"
age = 18
print("Name:", name)
print("Age next year:", age + 1)
score = 78
if score >= 50:
print("Pass")
else:
print("Try again")
languages = ["Python", "JavaScript", "HTML"]
for language in languages:
print("I am learning", language)
def add_numbers(a, b):
total = a + b
return total
answer = add_numbers(5, 7)
print(answer)
name = input("What is your name? ")
print("Hello", name)
message = " python is fun "
clean = message.strip()
print(clean.upper())
marks = [80, 75, 90]
total = 0
for mark in marks:
total = total + mark
print("Total:", total)
student = {
"name": "Kiruthika",
"grade": "A"
}
print(student["name"])
print(student["grade"])
count = 1
while count <= 5:
print(count)
count = count + 1
text = "42"
try:
number = int(text)
print(number + 8)
except ValueError:
print("Not a number")
length = 12
width = 5
area = length * width
print("Area:", area)
def greet(name):
return "Hello, " + name
user_name = input("Enter your name: ")
message = greet(user_name)
print(message)
age = 20
has_id = True
if age >= 18:
if has_id:
print("Entry allowed")
else:
print("ID required")
else:
print("Too young")
numbers = [1, 2, 3, 4, 5, 6]
even_numbers = []
for number in numbers:
if number % 2 == 0:
even_numbers.append(number)
print(even_numbers)
words = ["cat", "python", "code"]
for word in words:
length = len(word)
print(word, "has", length, "letters")
scores = [45, 92, 68, 88]
largest = scores[0]
for score in scores:
if score > largest:
largest = score
print("Highest score:", largest)
choice = "2"
if choice == "1":
print("Start game")
elif choice == "2":
print("Open settings")
else:
print("Exit")
sales = [120, 80, 150, 90]
total = sum(sales)
average = total / len(sales)
print("Total sales:", total)
print("Average sale:", average)
This beginner summary is adapted from the Python Tutorial sections on the informal introduction, control flow, and data structures.