Core Python — Basic (50+ Coding Exercises)
- Write a program that reads two integers and prints their sum, difference, product, and quotient (handle division by zero).
- Write a program that reads a string and prints it reversed.
- Write a program that checks whether a number is even or odd.
- Write a program that finds the maximum of three numbers.
- Write a program that computes the factorial of (n) (iterative).
- Write a program that prints the first (n) Fibonacci numbers.
- Write a program that checks if a number is prime.
- Write a program that prints all primes up to (n).
- Write a program that counts vowels in a string.
- Write a program that checks if a string is a palindrome (ignore spaces).
- Write a program that sums all numbers in a list.
- Write a program that finds the second-largest number in a list.
- Write a program that removes duplicates from a list (preserve order).
- Write a program that merges two lists and sorts the result.
- Write a program that counts occurrences of each word in a sentence.
- Write a program that finds the most frequent character in a string.
- Write a program that converts Celsius to Fahrenheit and vice versa.
- Write a program that computes simple interest and compound interest.
- Write a program that prints a right triangle pattern of
*of height (n). - Write a program that prints a multiplication table for a given number up to 10.
- Write a program that computes the sum of digits of an integer.
- Write a program that computes the digital root of a number.
- Write a program that checks whether two strings are anagrams.
- Write a program that splits a list into chunks of size (k).
- Write a program that rotates a list right by (k).
- Write a program that finds common elements between two lists (unique output).
- Write a program that finds intersection and union of two sets.
- Write a program that safely reads an integer from input until valid.
- Write a program that uses a dict as a phonebook (add/search/delete).
- Write a program that sorts a dictionary by values.
- Write a program that counts how many times each letter appears (a–z only).
- Write a program that removes punctuation from a string.
- Write a program that replaces multiple spaces with a single space.
- Write a program that finds the longest word in a sentence.
- Write a program that generates a list of squares from 1 to (n).
- Write a program that filters out negative numbers from a list.
- Write a program that reads a file and counts the number of lines, words, and characters.
- Write a program that copies a text file to another file.
- Write a program that appends a new line to a file.
- Write a program that reads a CSV-like file (comma-separated) and prints each row as a list.
- Write a function
is_leap_year(year)and test it with multiple inputs. - Write a function
gcd(a, b)using Euclid’s algorithm. - Write a function
lcm(a, b)usinggcd. - Write a function that returns
(min, max)from a list (without using built-insmin/max). - Write a function that flattens a 2D list into 1D.
- Write a function that counts how many times a substring appears in a string (overlapping allowed).
- Write a function that validates a password (min length, digit, uppercase, lowercase).
- Write a program that simulates a basic calculator loop until user types
quit. - Write a program that converts an integer to binary (without using
bin()). - Write a program that converts a binary string to integer (without using
int(x, 2)). - Write a program that finds the first non-repeating character in a string.
- Write a program that checks if a list is sorted (ascending).