Verified example programs
Short, complete programs that show one idea at a time. Each example includes the code, the exact output, and an explanation you can read before or after running it.
Examples
30
Categories
16
Runs locally
In your browser
Use the modulo operator and an if-else statement to classify an integer.
Combine conditions with and to find the maximum of three values.
Combine divisibility rules to decide whether a year is a leap year.
Map a numeric score to a letter grade using an if-elif ladder.
Print a ten-row multiplication table with a for loop and range().
Multiply numbers in a loop to compute n! with a loop.
Generate the first n Fibonacci numbers with parallel assignment.
Add the first n natural numbers with a loop and compare the closed formula.
Normalize a phrase and compare it with its reverse to detect a palindrome.
Count the vowels in a sentence with a loop and a membership test.
Transform a sentence with the title() string method.