25 Fun Python Codes For Newbies, Study Guides, Projects, Research of Computer science

Hands on fun codes for beginners to try out in python! (features output and the working idea behind each code) Index 1.Age Checker 2.While Loop with continue 3.Even / Odd Checker 4.Vowel counter 5.Largest Number 6.Reverse a String 7.Sum of Digits 8.Word Counter 9.Prime Number Checker 10.Uppercase Counter 11.Palindrome Checker 12.Multiply List numbers 13.Numbers Divisible by 3 14.Digit Counter 15.Smallest Number 16.Consonant Counter 17.Star Pattern 18.Even Numbers in Range 19.Replace Spaces 20.Sum of Even Numbers 21.Remove Vowels 22.Multiplication Table 23.Print N Natural Numbers 24.Count Character Occurrences 25.Leap Year Checker

Typology: Study Guides, Projects, Research

2025/2026

Available from 05/24/2026

aadya-singh-2
aadya-singh-2 🇮🇳

4 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
INDEX
Program
No. Name / Description Purpose / What it Does
1 Age Checker Classifies age into "young", "teenager", or
"adult"
2While Loop with
Continue
Demonstrates while loop, continue statement,
and else block
3 Even / Odd Checker Checks each number in a list and prints if it is
even or odd
4 Vowel Counter Counts the number of vowels in a word
5 Largest Number Finds the largest number in a list
6 Reverse a String Reverses the input string
7 Sum of Digits Calculates the sum of digits of a number
8 Word Counter Counts the number of words in a sentence
9 Prime Number Checker Checks if a number is prime or not
10 Uppercase Counter Counts the number of uppercase letters in
text
11 Palindrome Checker Checks if a word is a palindrome
12 Multiply List Numbers Multiplies all numbers in a list
13 Numbers Divisible by 3 Prints numbers from 1 to 30 divisible by 3
14 Digit Counter Counts number of digits in a number
15 Smallest Number Finds the smallest number in a list
16 Consonant Counter Counts consonants in text
17 Star Pattern Prints a simple triangle star pattern
18 Even Numbers in Range Prints all even numbers in a user-defined
range
19 Replace Spaces Replaces all spaces in text with hyphens
20 Sum of Even Numbers Calculates the sum of all even numbers in a
list
21 Remove Vowels Removes vowels from the text
22 Multiplication Table Prints the multiplication table of a number
23 Print N Natural
Numbers Prints first N natural numbers
24 Count Character
Occurrences
Counts how many times a specific character
occurs in text
25 Leap Year Checker Checks whether a year is a leap year or not
Outputs have been given in boxes
1 | P a g e
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download 25 Fun Python Codes For Newbies and more Study Guides, Projects, Research Computer science in PDF only on Docsity!

INDEX

Program No. Name / Description Purpose / What it Does 1 Age Checker Classifies age into "young", "teenager", or "adult" 2 While Loop with Continue Demonstrates while loop, continue statement, and else block 3 Even / Odd Checker Checks each number in a list and prints if it is even or odd 4 Vowel Counter Counts the number of vowels in a word 5 Largest Number Finds the largest number in a list 6 Reverse a String Reverses the input string 7 Sum of Digits Calculates the sum of digits of a number 8 Word Counter Counts the number of words in a sentence 9 Prime Number Checker Checks if a number is prime or not 10 Uppercase Counter Counts the number of uppercase letters in text 11 Palindrome Checker Checks if a word is a palindrome 12 Multiply List Numbers Multiplies all numbers in a list 13 Numbers Divisible by 3 Prints numbers from 1 to 30 divisible by 3 14 Digit Counter Counts number of digits in a number 15 Smallest Number Finds the smallest number in a list 16 Consonant Counter Counts consonants in text 17 Star Pattern Prints a simple triangle star pattern 18 Even Numbers in Range Prints all even numbers in a user-defined range 19 Replace Spaces Replaces all spaces in text with hyphens 20 Sum of Even Numbers Calculates the sum of all even numbers in a list 21 Remove Vowels Removes vowels from the text 22 Multiplication Table Prints the multiplication table of a number 23 Print N Natural Numbers Prints first N natural numbers 24 Count Character Occurrences Counts how many times a specific character occurs in text 25 Leap Year Checker Checks whether a year is a leap year or not Outputs have been given in boxes

PROGRAMME 1

What it is intended to do:

  1. Asks the user to enter their age.
  2. If age is less than 13 → prints "You're so young!"
  3. If age is 13–17 → prints "You're a teenager!"
  4. If age is 18 or more → prints "You're an adult!"
  5. Prints "finished!" at the end age = int(input("Enter your age: ")) if age < 13: print("You're so young!") elif age < 18: print("You're a teenager!") else: print("You're an adult!") print("finished!") PROGRAMME 2 What it does:
  6. Starts with i = 1
  7. Runs a loop until i reaches 10
  8. In each loop: o Increases i by 1 o If i == 4, it skips printing using continue o Otherwise prints i - 1
  9. After loop ends, prints "finished!" i= while i<10: i += if i==4: continue print(i-1) else: print("finished!") PROGRAMME 3 What it does: 2 | P a g e You're a teenager! Finished! Input: 15 1 2 3 5 6 7 8 9 10 finished! No input required 3 is Odd 4 is Even 7 is Odd 10 is Even Input: 3 4 7 10
  1. Loops through all numbers: o Converts each to integer. o Compares it with largest. o Updates largest if a bigger number is found.
  2. Prints the largest number. numbers = input("Enter numbers separated by spaces: ").split() largest = int(numbers[0]) for num in numbers: num = int(num) if num > largest: largest = num print("Largest number is:", largest) PROGRAMME 6 What it does:
  3. Takes a text input from the user.
  4. Starts with an empty string reversed_text.
  5. Loops through each character in the original text.
  6. Adds each character in front of reversed_text.
  7. Prints the reversed string. text = input("Enter some text: ") reversed_text = "" for ch in text: reversed_text = ch + reversed_text print("Reversed text:", reversed_text) PROGRAMME 7 What it does:
  8. Takes a number as input (as a string).
  9. Initializes total = 0.
  10. Loops through each digit (character) in the number.
  11. Converts each digit to integer and adds it to total. Reversed text: olleh Input: hello Sum of digits: 10 Input: 1234
  1. Prints the sum of digits. num = input("Enter a number: ") total = 0 for digit in num: total += int(digit) print("Sum of digits:", total) PROGRAMME 8 What it does:
  2. Takes a sentence as input.
  3. Splits the sentence into words using spaces.
  4. Stores the words in a list.
  5. Uses len() to count how many words are in the list.
  6. Prints the number of words. sentence = input("Enter a sentence: ") words = sentence.split() print("Number of words:", len(words)) PROGRAMME 9 What it is intended to do:
  7. Takes a number as input.
  8. Assumes the number is prime (is_prime = True).
  9. Checks divisibility from 2 to num-1.
  10. If divisible by any number: o Marks it as not prime o Stops the loop.
  11. Prints whether the number is Prime or Not Prime. num = int(input("Enter a number: ")) is_prime = True for i in range(2, num): if num % i == 0: is_prime = False break if num > 1 and is_prime: Number of words: 4 Input: Python is very easy Prime number Input: 7
  1. Splits them into a list.
  2. Starts with result = 1.
  3. Loops through each number: o Converts it to integer. o Multiplies it with result.
  4. Prints the final multiplication result. nums = input("Enter numbers: ").split() result = 1 for n in nums: result *= int(n) print("Result:", result) PROGRAMME 13 What it does:
  5. Runs a loop from 1 to 30.
  6. Checks if the number is divisible by 3.
  7. Prints the number if divisible by 3. for i in range(1, 31): if i % 3 == 0: print(i) PROGRAMME 14 What it does:
  8. Takes a number as input (as text).
  9. Uses len() to count how many characters (digits) are in it.
  10. Prints the total number of digits. num = input("Enter a number: ") print("Digits:", len(num)) PROGRAMME 15  Takes multiple numbers as input.  Stores the first number as smallest.  Loops through all numbers:  Converts each to integer.  Compares it with smallest

No input required Digits: 5 Input: 50492 Smallest number: 1 Input: 8 3 10 1 6

nums = input("Enter numbers: ").split() smallest = int(nums[0]) for n in nums: n = int(n) if n < smallest: smallest = n print("Smallest number:", smallest) PROGRAMME 16 What it does:

  1. Takes a text input.
  2. Converts text to lowercase.
  3. Loops through each character.
  4. Checks: o Character is a letter (isalpha()). o Character is not a vowel.
  5. Counts consonants.
  6. Prints the total number. text = input("Enter text: ") count = 0 for ch in text.lower(): if ch.isalpha() and ch not in "aeiou": count += 1 print("Consonants:", count) PROGRAMME 17 What it does:
  7. Runs a loop from 1 to 5.
  8. Prints * multiplied by the loop number.
  9. Produces a triangle pattern. for i in range(1, 6): print("*" * i) Consonants: 7 Input: Hello World

**

No input required

n = int(n) if n % 2 == 0: total += n print("Sum of even numbers:", total) PROGRAMME 21 What it does:

  1. Takes text input.
  2. Starts with an empty string result.
  3. Loops through each character in the text.
  4. Checks if the character is not a vowel (a, e, i, o, u) ignoring case.
  5. Adds it to result.
  6. Prints the text without vowels. text = input("Enter text: ") result = "" for ch in text: if ch.lower() not in "aeiou": result += ch print(result) PROGRAMME 22 What it does:
  7. Takes a number as input.
  8. Loops from 1 to 10.
  9. Prints the multiplication table in the format: num x i = result. num = int(input("Enter a number: ")) for i in range(1, 11): print(num, "x", i, "=", num * i) PROGRAMME 23 What it does:
  10. Takes an integer n.
  11. Loops from 1 to n. 10 | P a g e Hll Wrld Input: Hello World 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50 Input: 5 1 2 3 4 5 Input: 5
  1. Prints each number. n = int(input("Enter N: ")) for i in range(1, n + 1): print(i) PROGRAMME 24 What it does:
  2. Takes text input.
  3. Takes a single character input.
  4. Loops through each character in the text.
  5. Counts how many times the character appears.
  6. Prints the total occurrences. text = input("Enter text: ") ch = input("Enter a character: ") count = 0 for c in text: if c == ch: count += 1 print("Occurrences:", count) PROGRAMME 25 What it does:
  7. Takes a year as input.
  8. Checks leap year conditions: o Divisible by 4 and not divisible by 100, OR o Divisible by 400
  9. Prints "Leap year" or "Not a leap year". year = int(input("Enter a year: ")) if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): print("Leap year") else: Occurrences: 3 Input: Text: banana, Character: a Leap year Input: 2024