Hackforge Academy

Category: python

python coding questions

Published on 05 Mar 2026

Explanation

Write a Python program to reverse a string using slicing.

Code:

def reverse_string(s):
    return s[::-1]

print(reverse_string("Python"))

Explanation

Write a Python program to calculate the factorial of a number using a loop.

Code:

def factorial(n):
    fact = 1
    for i in range(1, n + 1):
        fact *= i
    return fact

print(factorial(5))

Explanation

Write a Python program to check whether a given number is prime.

Code:

def is_prime(num):
    if num <= 1:
        return False
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False
    return True

print(is_prime(7))

Explanation

Write a Python program to print the Fibonacci series up to n terms.

Code:

def fibonacci(n):
    a, b = 0, 1
    for _ in range(n):
        print(a, end=" ")
        a, b = b, a + b

fibonacci(10)

Explanation

Write a Python program to count the frequency of each character in a string using a dictionary.

Code:

def count_characters(s):
    freq = {}
    for char in s:
        freq[char] = freq.get(char, 0) + 1
    return freq

print(count_characters("hello"))

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community