0% found this document useful (0 votes)
2 views10 pages

Python Programs for Beginners

Uploaded by

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

Python Programs for Beginners

Uploaded by

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

1.

Hello World

This program prints a simple greeting.

# Hello World print("Hello, World!")


2. Sum of Two Numbers

This program adds two numbers entered by the user.

# Sum of two numbers a = int(input("Enter first number: ")) b = int(input("Enter


second number: ")) print("Sum =", a + b)
3. Factorial of a Number

This program calculates a factorial using a loop.

# Factorial program num = int(input("Enter a number: ")) f = 1 for i in range(1,


num+1): f *= i print("Factorial =", f)
4. Fibonacci Series

Prints Fibonacci sequence for n terms.

# Fibonacci series n = int(input("Enter terms: ")) a, b = 0, 1 for _ in range(n):


print(a) a, b = b, a+b
5. Check Even or Odd

Determines whether a number is even or odd.

# Even or odd n = int(input("Enter a number: ")) if n % 2 == 0: print("Even") else:


print("Odd")
6. Simple Calculator

Basic calculator performing +, -, *, /.

# Simple calculator a = float(input("Enter number 1: ")) b = float(input("Enter


number 2: ")) op = input("Enter operator (+,-,*,/): ") if op == '+': print(a+b) elif
op == '-': print(a-b) elif op == '*': print(a*b) elif op == '/': print(a/b) else:
print("Invalid operator")
7. Reverse a String

Reverses a user-input string.

# Reverse string s = input("Enter a string: ") print("Reversed:", s[::-1])


8. Largest of Three Numbers

Finds the biggest among three numbers.

# Largest of three numbers a = int(input("a: ")) b = int(input("b: ")) c =


int(input("c: ")) print("Largest =", max(a, b, c))
9. Count Vowels in String

Counts number of vowels in a string.

# Count vowels s = input("Enter text: ").lower() vowels = 'aeiou' count = sum(1 for
ch in s if ch in vowels) print("Vowel count =", count)
10. Simple Interest Calculator

Calculates simple interest using formula SI = (P × R × T) / 100.

# Simple Interest P = float(input("Principal: ")) R = float(input("Rate: ")) T =


float(input("Time: ")) SI = (P * R * T) / 100 print("Simple Interest =", SI)

You might also like