0% found this document useful (0 votes)
7 views4 pages

Python Programming Basics: 15 Examples

The document contains 15 simple Python programs that demonstrate basic programming concepts. These include printing 'Hello World', performing arithmetic operations, checking for prime numbers, and manipulating strings and numbers. Each program is designed to illustrate fundamental programming techniques and user input handling.

Uploaded by

akshitkumar3310
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Python Programming Basics: 15 Examples

The document contains 15 simple Python programs that demonstrate basic programming concepts. These include printing 'Hello World', performing arithmetic operations, checking for prime numbers, and manipulating strings and numbers. Each program is designed to illustrate fundamental programming techniques and user input handling.

Uploaded by

akshitkumar3310
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program 1: Hello World

print("Hello, World!")

Program 2: Add Two Numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum =", a + b)

Program 3: Largest of Two Numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

if a > b:
print(a, "is greater")
else:
print(b, "is greater")

Program 4: Even or Odd


num = int(input("Enter a number: "))

if num % 2 == 0:
print("Even number")
else:
print("Odd number")

Program 5: Factorial
n = int(input("Enter a number: "))
fact = 1

for i in range(1, n + 1):


fact = fact * i

print("Factorial =", fact)

Program 6: Fibonacci Series


n = int(input("Enter number of terms: "))
a, b = 0, 1

print(a, b, end=" ")


for i in range(2, n):
c=a+b
print(c, end=" ")
a, b = b, c

Program 7: Prime Number Check


num = int(input("Enter a number: "))
flag = 0

for i in range(2, num):


if num % i == 0:
flag = 1
break

if flag == 0:
print("Prime number")
else:
print("Not a prime number")

Program 8: Reverse a Number


num = int(input("Enter number: "))
rev = 0

while num > 0:


rev = rev * 10 + num % 10
num = num // 10

print("Reversed number =", rev)

Program 9: Palindrome String


s = input("Enter a string: ")

if s == s[::-1]:
print("Palindrome")
else:
print("Not a palindrome")

Program 10: Sum of Digits


num = int(input("Enter number: "))
total = 0

while num > 0:


total += num % 10
num //= 10

print("Sum of digits =", total)

Program 11: Count Vowels


s = input("Enter a string: ")
count = 0

for ch in s:
if ch in "aeiouAEIOU":
count += 1

print("Number of vowels =", count)

Program 12: 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 13: Multiplication Table


n = int(input("Enter a number: "))

for i in range(1, 11):


print(n, "x", i, "=", n * i)

Program 14: Greatest 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 greatest")
elif b > c:
print(b, "is greatest")
else:
print(c, "is greatest")
Program 15: Simple Calculator
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print("[Link] [Link] [Link] [Link]")


choice = int(input("Enter choice: "))

if choice == 1:
print("Result =", a + b)
elif choice == 2:
print("Result =", a - b)
elif choice == 3:
print("Result =", a * b)
elif choice == 4:
print("Result =", a / b)
else:
print("Invalid choice")

You might also like