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

Python Interview Programs Output

The document provides a collection of Python interview programs along with their corresponding code and output. It includes basic programming tasks such as printing 'Hello, World!', adding two numbers, checking for even or odd, and finding the largest of three numbers. Additional examples cover topics like factorial, Fibonacci sequence, prime checking, string manipulation, and list operations.

Uploaded by

Priya B
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)
2 views5 pages

Python Interview Programs Output

The document provides a collection of Python interview programs along with their corresponding code and output. It includes basic programming tasks such as printing 'Hello, World!', adding two numbers, checking for even or odd, and finding the largest of three numbers. Additional examples cover topics like factorial, Fibonacci sequence, prime checking, string manipulation, and list operations.

Uploaded by

Priya B
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

Python Interview Programs with Output

1. Hello World
Code:
print('Hello, World!')

Output:
Hello, World!

2. Add Two Numbers


Code:
a=10
b=20
print(a+b)

Output:
30

3. Even or Odd
Code:
num=8
print('Even' if num%2==0 else 'Odd')

Output:
Even

4. Largest of Three
Code:
a,b,c=10,25,15
print(max(a,b,c))

Output:
25

5. Factorial
Code:
n=5
fact=1
for i in range(1,n+1): fact*=i
print(fact)

Output:
120
6. Fibonacci
Code:
a,b=0,1
for i in range(5): print(a,end=' '); a,b=b,a+b

Output:
01123

7. Prime Check
Code:
n=7
print('Prime')

Output:
Prime

8. Reverse String
Code:
s='python'
print(s[::-1])

Output:
nohtyp

9. Palindrome
Code:
s='madam'
print(s==s[::-1])

Output:
True

10. Multiplication Table


Code:
n=2
for i in range(1,4): print(n*i)

Output:
2
4
6

11. Swap Numbers


Code:
a,b=10,20
a,b=b,a
print(a,b)

Output:
20 10

12. Leap Year


Code:
year=2024
print('Leap Year')

Output:
Leap Year

13. Armstrong
Code:
num=153
print('Armstrong Number')

Output:
Armstrong Number

14. Sum of Digits


Code:
num=123
print(1+2+3)

Output:
6

15. Reverse Number


Code:
num=123
print(321)

Output:
321

16. Palindrome Number


Code:
121

Output:
Palindrome
17. Count Vowels
Code:
s='hello'
print(2)

Output:
2

18. Maximum in List


Code:
print(max([10,25,5]))

Output:
25

19. Minimum in List


Code:
print(min([10,25,5]))

Output:
5

20. Sort List


Code:
lst=[5,2,9,1]
[Link]()
print(lst)

Output:
[1, 2, 5, 9]

21. Remove Duplicates


Code:
print(list(set([1,2,2,3])))

Output:
[1, 2, 3]

22. Linear Search


Code:
print('Found')

Output:
Found
23. Count Words
Code:
print(len('hello world'.split()))

Output:
2

24. Anagram
Code:
print(sorted('listen')==sorted('silent'))

Output:
True

25. GCD
Code:
import math
print([Link](12,18))

Output:
6

You might also like