Basic Python Programs

Fundamental Python programs to get started with syntax, I/O, and basic problem solving.

25 program solutions

Back to Topics

Program Solutions

1

Print "Hello, World!"

Your very first Python program that prints "Hello, World!" to the screen.

Beginner
View Solution
2

Add Two Numbers

Read two numbers from the user, add them, and display the result.

Beginner
View Solution
3

Swap Two Variables

Swap the values of two variables using a temporary variable and Python’s tuple unpacking.

Beginner
View Solution
4

Find ASCII Value of a Character

Read a character from the user and print its ASCII (Unicode code point) value.

Beginner
View Solution
5

Check Even or Odd

Check whether a given integer number is even or odd.

Beginner
View Solution
6

Find Largest of Two Numbers

Compare two numbers and print the larger one (or that they are equal).

Beginner
View Solution
7

Find Largest of Three Numbers

Compare three numbers and print the largest one (or that some/all are equal).

Beginner
View Solution
8

Check Positive, Negative, or Zero

Determine whether a given number is positive, negative, or zero.

Beginner
View Solution
9

Convert Kilometers to Miles

Convert a distance given in kilometers to miles using a standard conversion factor.

Beginner
View Solution
10

Convert Celsius to Fahrenheit

Convert temperature from Celsius to Fahrenheit using the standard formula.

Beginner
View Solution
11

Calculate Area of a Triangle

Calculate the area of a triangle given its base and height.

Beginner
View Solution
12

Calculate Simple Interest

Calculate simple interest given principal, rate, and time.

Beginner
View Solution
13

Calculate Compound Interest

Calculate compound interest given principal, rate, time, and number of times interest is compounded per year.

Beginner
View Solution
14

Calculate Square Root

Calculate the square root of a number using the math module.

Beginner
View Solution
15

Convert Seconds to Hours, Minutes, and Seconds

Convert a time duration in total seconds to hours, minutes, and seconds.

Beginner
View Solution
16

Calculate Body Mass Index (BMI)

Calculate BMI from weight (kg) and height (meters) and classify the result.

Beginner
View Solution
17

Check Leap Year

Determine whether a given year is a leap year using the Gregorian calendar rules.

Beginner
View Solution
18

Find Absolute Value

Compute the absolute value of a number without using the built-in abs() directly.

Beginner
View Solution
19

Calculate Age from Birth Year

Calculate current age from a given birth year using the current year.

Beginner
View Solution
20

Sum of First N Natural Numbers

Compute the sum of the first N natural numbers using a formula.

Beginner
View Solution
21

Calculate Power Without Using pow()

Raise a number to an integer power using a loop instead of the built-in pow() or **.

Beginner
View Solution
22

Print Multiplication Table

Print the multiplication table for a given number up to 10 (or a user-defined limit).

Beginner
View Solution
23

Convert Decimal to Binary

Convert a non-negative integer from decimal to binary representation.

Beginner
View Solution
24

Convert Binary to Decimal

Convert a binary string (e.g. 1010) to its decimal integer value.

Beginner
View Solution
25

Calculate Electricity Bill

Calculate an electricity bill based on units consumed using a simple slab system.

Beginner
View Solution