This third series of Python exercises introduces algorithmic challenges designed to help beginners strengthen their logical thinking and problem-solving skills. Through tasks like Fibonacci generation, palindrome detection, divisor computation, and list processing, learners move beyond basic syntax into real programming logic. Perfect for those ready to take their first steps into algorithmic thinking while still staying within a beginner-friendly level.
Level: Beginner → Intermediate transition Focus: Logic, loops, conditions, math reasoning, small algorithms
Exercise 1 — Sum of the First N Natural Numbers
Objective: Practice loops and accumulation logic. Task: Ask the user for a number N and compute the sum: 1 + 2 + 3 + … + N
n = int(input("Enter a positive integer N: "))
total = 0
for i in range(1, n + 1):
total += i
print("Sum of first", n, "natural numbers is:", total)
Exercise 2 — Find the Second Largest Number in a List
Objective: Sorting logic + list manipulation. Task: Given a list of numbers, print the second largest value without using max() twice.
numbers = [10, 5, 8, 20, 3, 20]
unique = list(set(numbers)) # remove duplicates
unique.sort(reverse=True) # sort descending
if len(unique) < 2:
print("No second largest number.")
else:
print("Second largest number is:", unique[1])
Exercise 3 — Count How Many Times a Value Appears
Objective: Frequency counting algorithm. Task: Ask the user for a list and a target number → count how many times it appears.
nums_str = input("Enter numbers separated by spaces: ")
target = input("Enter the value to count: ")
numbers = nums_str.split()
count = 0
for n in numbers:
if n == target:
count += 1
print("The value", target, "appears", count, "time(s).")
Exercise 4 — Palindrome Checker
Objective: String manipulation + logic. Task: Write a program that checks if a given word is a palindrome (same forwards and backwards).
word = input("Enter a word: ")
clean = word.lower()
if clean == clean[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Exercise 5 — Find All Divisors of a Number
Objective: Use loops to compute divisors. Task: Ask the user for a number and print all integers that divide it evenly.
num = int(input("Enter a positive integer: "))
print("Divisors of", num, "are:")
for i in range(1, num + 1):
if num % i == 0:
print(i)
Exercise 6 — FizzBuzz
Objective: Classic programming challenge combining modulus and conditions. Task: Print numbers from 1 to 50:
“Fizz” if divisible by 3
“Buzz” if divisible by 5
“FizzBuzz” if divisible by both
for i in range(1, 51):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
Exercise 7 — Compute the Factorial of a Number
Objective: Loop-based algorithm + multiplication accumulation. Task: Ask the user for a number N and compute N! (factorial).
n = int(input("Enter a non-negative integer: "))
factorial = 1
for i in range(1, n + 1):
factorial *= i
print(str(n) + "! =", factorial)
Exercise 8 — Remove All Even Numbers from a List
Objective: Filtering algorithm. Task: Given a list, build a new list containing only the odd numbers.
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
odds = []
for n in numbers:
if n % 2 != 0:
odds.append(n)
print("Original list:", numbers)
print("Odd numbers only:", odds)
Exercise 9 — Find the Longest Word in a Sentence
Objective: String processing + iteration. Task: Ask the user for a sentence and print the longest word.
sentence = input("Enter a sentence: ")
words = sentence.split()
longest = ""
for w in words:
if len(w) > len(longest):
longest = w
print("Longest word is:", longest)
print("Length:", len(longest))
Exercise 10 — Generate the First N Fibonacci Numbers
Objective: Sequence generation + iterative thinking. Task: Ask the user for a number N and print the first N numbers of the Fibonacci sequence.
n = int(input("How many Fibonacci numbers? "))
a, b = 0, 1
for _ in range(n):
print(a)
a, b = b, a + b
💬 Comments
No comments yet. Be the first to comment!
Login to comment.