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

15 Python Programs With Outputs

The document contains 15 Python programs along with their outputs, showcasing various programming concepts. Examples include printing 'Hello World', performing arithmetic operations, checking for even or odd numbers, calculating factorials, and more. Each program is presented with its corresponding output for clarity.
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)
21 views4 pages

15 Python Programs With Outputs

The document contains 15 Python programs along with their outputs, showcasing various programming concepts. Examples include printing 'Hello World', performing arithmetic operations, checking for even or odd numbers, calculating factorials, and more. Each program is presented with its corresponding output for clarity.
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

15 Python Programs with Outputs

Hello World
Program:
print("Hello World")
Output:
Hello World

Addition of Two Numbers


Program:
a = 10
b=5
c=a+b
print("Sum =", c)
Output:
Sum = 15

Even or Odd
Program:
num = 7
if num % 2 == 0:
print("Even")
else:
print("Odd")
Output:
Odd

Factorial (5)
Program:
n=5
fact = 1
for i in range(1, n+1):
fact *= i
print("Factorial =", fact)
Output:
Factorial = 120

Multiplication Table (3)


Program:
n=3
for i in range(1, 6):
print(n, "x", i, "=", n*i)
Output:
3x1=3
3x2=6
3x3=9
3 x 4 = 12
3 x 5 = 15

Simple Interest
Program:
p = 1000
r=5
t=2
si = (p*r*t)/100
print("SI =", si)
Output:
SI = 100.0

Largest of Three Numbers


Program:
a, b, c = 4, 9, 2
print("Largest =", max(a,b,c))
Output:
Largest = 9

Count Vowels
Program:
text = "python"
count = 0
for ch in text:
if ch in "aeiou":
count += 1
print("Vowels =", count)
Output:
Vowels = 1

Reverse String
Program:
s = "Python"
print(s[::-1])
Output:
nohtyP

List Sum
Program:
nums = [1,2,3,4]
print("Sum =", sum(nums))
Output:
Sum = 10

Prime Number Check (11)


Program:
n = 11
for i in range(2, n):
if n % i == 0:
print("Not Prime")
break
else:
print("Prime")
Output:
Prime

Fibonacci (5 terms)
Program:
a,b = 0,1
for _ in range(5):
print(a, end=" ")
a,b = b,a+b
Output:
01123

Square Numbers
Program:
for i in range(1,6):
print(i**2)
Output:
1
4
9
16
25

Dictionary Example
Program:
d = {"a":1,"b":2}
for k,v in [Link]():
print(k,v)
Output:
a1
b2
Palindrome Check
Program:
s="madam"
if s==s[::-1]:
print("Palindrome")
else:
print("Not")
Output:
Palindrome

You might also like