50 python programs that will help in developing basic logic and coding practice


50 python programs


Building strong logic in Python is best achieved by moving from simple input/output to data structures and algorithms. 

You should be able to code these 50 Python practice programs without any external help of use of AI.

The programs are categorized by the concepts they reinforce.

How to practice effectively:

  • Don't copy-paste: Type every line yourself to build muscle memory.

  • Use Comments: Explain to yourself what each block of code does.

  • Debug manually: If a program fails, try to "be the computer" and trace the variables on paper.


1. Basic Syntax and Math (1–10)

These focus on variables, operators, and basic user input.

  1. Hello World: Print your name and favorite color.

  2. Simple Calculator: Add, subtract, multiply, and divide two numbers.

  3. Area of a Circle: Calculate area given radius using A = pi r^2

  4. Temperature Converter: Convert Celsius to Fahrenheit.

  5. Swap Two Variables: Swap values using a third variable and without one.

  6. Miles to Kilometers: Convert distances using a conversion factor.

  7. Calculate Interest: Find Simple Interest (P x R x T) / 100

  8. Square Root: Find the square root of a number.

  9. Area of a Triangle: Use Heron's formula or base/height.

  10. BMI Calculator: Calculate Body Mass Index based on weight and height.

2. Conditional Logic (11–20)

These focus on if-else statements and decision-making.

  1. Odd or Even: Check if a number is divisible by 2.

  2. Leap Year: Determine if a year is a leap year.

  3. Largest of Three: Find the maximum among three numbers.

  4. Positive/Negative: Check if a number is positive, negative, or zero.

  5. Vowel or Consonant: Check if an input character is a vowel.

  6. Grade Calculator: Assign grades (A, B, C) based on percentage.

  7. Password Validator: Check if a string matches a preset password.

  8. Vote Eligibility: Check if a user is 18 or older.

  9. Divisibility Check: See if a number is divisible by both 5 and 11.

  10. Triangle Validity: Check if three angles sum up to 180°.

3. Loops and Iteration (21–30)

These focus on for and while loops.

  1. Multiplication Table: Print the table for any given number.

  2. Sum of Natural Numbers: Find the sum of the first N numbers.

  3. Factorial: Calculate n! using a loop.

  4. Fibonacci Sequence: Generate the sequence up to N terms.

  5. Reverse a Number: Turn 123 into 321.

  6. Palindrome Check: Check if a string or number reads the same backward.

  7. Prime Number: Determine if a number is prime.

  8. Armstrong Number: Check if the sum of cubes of digits equals the number.

  9. Count Digits: Count the number of digits in an integer.

  10. Pattern Printing: Print a right-angled triangle of stars (*).

4. Lists and Data Structures (31–40)

These focus on managing collections of data.

  1. Sum of List: Add all elements in a list.

  2. Largest in List: Find the maximum value in an array.

  3. Remove Duplicates: Create a unique list from one with repeats.

  4. List Reversal: Reverse a list without using [::-1].

  5. Find Element: Check if a specific value exists in a list.

  6. Common Elements: Find the intersection of two lists.

  7. Even Numbers in List: Extract only even numbers into a new list.

  8. Count Occurrences: Count how many times $X$ appears in a list.

  9. Sort a List: Sort elements using the .sort() method or Bubble Sort.

  10. Matrix Addition: Add two 2x2 matrices using nested lists.

5. Strings and Functions (41–50)

These focus on text manipulation and modular code.

  1. Count Vowels: Count the number of vowels in a string.

  2. Remove Punctuation: Clean a string of all symbols.

  3. Word Counter: Count the number of words in a sentence.

  4. Anagram Check: Check if two strings contain the same characters.

  5. Recursive Factorial: Solve factorial using a function that calls itself.

  6. Upper/Lower Counter: Count uppercase and lowercase letters.

  7. Find the Longest Word: Identify the longest word in a list of words.

  8. Binary to Decimal: Convert a binary string to a base-10 integer.

  9. Dictionary Practice: Create a phonebook using name-number pairs.

  10. Random Guessing Game: The computer picks a number; the user tries to guess it.


Main category
Address

OpenSourceCook.in
"Natraj"  Bungalow,
Colony No.7,  Sr.No. 38.
(Lane Behind Sai Baba Mandir)
Kale Borate Nagar, Hadapsar,
Pune - 411028.
Get Directions