Program to print “Hello World”
print("Hello World")
Program to input a name and age and print a greeting
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Hello", name, "You are", age, "years old.")
Program to find sum, difference, product, and quotient
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum =", a + b)
print("Difference =", a - b)
print("Product =", a * b)
print("Quotient =", a / b)
Program to check whether a number is even or odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
Program to find the largest of two numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a > b:
print(a, "is largest")
else:
print(b, "is largest")
Program to find the largest of three numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a > b and a > c:
print(a, "is largest")
elif b > c:
print(b, "is largest")
else:
print(c, "is largest")
Program to check positive, negative, or zero
num = int(input("Enter a number: "))
if num > 0:
print("Positive number")
elif num < 0:
print("Negative number")
else:
print("Zero")
Program to swap two numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
a, b = b, a
print("After swapping:", a, b)
Program to calculate Simple Interest
p = float(input("Enter principal: "))
r = float(input("Enter rate: "))
t = float(input("Enter time: "))
si = (p * r * t) / 100
print("Simple Interest =", si)
Program to calculate Area
a) Circle
r = float(input("Enter radius: "))
area = 3.14 * r * r
print("Area of circle =", area)
b) Rectangle
l = float(input("Enter length: "))
b = float(input("Enter breadth: "))
print("Area of rectangle =", l * b)
c) Triangle
b = float(input("Enter base: "))
h = float(input("Enter height: "))
print("Area of triangle =", 0.5 * b * h)
Program to convert Celsius to Fahrenheit
c = float(input("Enter temperature in Celsius: "))
f = (c * 9/5) + 32
print("Temperature in Fahrenheit =", f)
Program to check Leap Year
year = int(input("Enter year: "))
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
print("Leap Year")
else:
print("Not a Leap Year")
Program to print numbers from 1 to N
n = int(input("Enter N: "))
for i in range(1, n + 1):
print(i)
Program to find sum of first N natural numbers
n = int(input("Enter N: "))
sum = 0
for i in range(1, n + 1):
sum += i
print("Sum =", sum)
Program to print even numbers in a range
start = int(input("Enter start: "))
end = int(input("Enter end: "))
for i in range(start, end + 1):
if i % 2 == 0:
print(i)
1️⃣6️⃣ Program to print multiplication table
n = int(input("Enter a number: "))
for i in range(1, 11):
print(n, "x", i, "=", n * i)
Program to calculate factorial
n = int(input("Enter a number: "))
fact = 1
for i in range(1, n + 1):
fact *= i
print("Factorial =", fact)
Program to reverse a number
num = int(input("Enter a number: "))
rev = 0
while num > 0:
rev = rev * 10 + num % 10
num = num // 10
print("Reversed number =", rev)
Program to generate Fibonacci series
n = int(input("Enter number of terms: "))
a, b = 0, 1
for i in range(n):
print(a, end=" ")
a, b = b, a + b