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

Python Practical List Answers

The document contains a series of practical Python programs that cover various topics such as input handling, number comparisons, string manipulations, and mathematical calculations. Each program is designed to demonstrate specific functionalities, including finding the largest or smallest numbers, checking for prime or composite status, generating Fibonacci series, and working with lists and dictionaries. Overall, it serves as a comprehensive guide for beginners to practice and enhance their Python programming skills.

Uploaded by

muneshofficially
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)
7 views3 pages

Python Practical List Answers

The document contains a series of practical Python programs that cover various topics such as input handling, number comparisons, string manipulations, and mathematical calculations. Each program is designed to demonstrate specific functionalities, including finding the largest or smallest numbers, checking for prime or composite status, generating Fibonacci series, and working with lists and dictionaries. Overall, it serves as a comprehensive guide for beginners to practice and enhance their Python programming skills.

Uploaded by

muneshofficially
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

PYTHON PRACTICAL PROGRAMS

1. Welcome Message
msg = input("Enter welcome message: ")
print("Message is:", msg)

2. Larger / Smaller of Two Numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a > b:
print("Larger:", a)
print("Smaller:", b)
else:
print("Larger:", b)
print("Smaller:", a)

3. Largest / Smallest of Three Numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
print("Largest:", max(a,b,c))
print("Smallest:", min(a,b,c))

4. Perfect, Armstrong, Palindrome


num = int(input("Enter number: "))
sum1 = 0
for i in range(1, num):
if num % i == 0:
sum1 += i
if sum1 == num:
print("Perfect Number")

temp = num
sum2 = 0
while temp > 0:
digit = temp % 10
sum2 += digit ** 3
temp //= 10
if sum2 == num:
print("Armstrong Number")

if str(num) == str(num)[::-1]:
print("Palindrome Number")

5. Prime or Composite
num = int(input("Enter number: "))
count = 0
for i in range(1, num+1):
if num % i == 0:
count += 1
if count == 2:
print("Prime Number")
else:
print("Composite Number")

6. 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

7. GCD and LCM


import math
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
gcd = [Link](a,b)
lcm = (a*b)//gcd
print("GCD:", gcd)
print("LCM:", lcm)

8. Count vowels, consonants, uppercase, lowercase


s = input("Enter string: ")
vowels = consonants = upper = lower = 0
for ch in s:
if [Link]():
if [Link]() in "aeiou":
vowels += 1
else:
consonants += 1
if [Link]():
upper += 1
if [Link]():
lower += 1
print("Vowels:", vowels)
print("Consonants:", consonants)
print("Uppercase:", upper)
print("Lowercase:", lower)

9. String Palindrome & Case Convert


s = input("Enter string: ")
if s == s[::-1]:
print("Palindrome")
else:
print("Not Palindrome")
print("Swap case:", [Link]())

10. Largest / Smallest in List


lst = list(map(int, input("Enter numbers: ").split()))
print("Largest:", max(lst))
print("Smallest:", min(lst))

11. Largest / Smallest in Tuple


t = tuple(map(int, input("Enter numbers: ").split()))
print("Largest:", max(t))
print("Smallest:", min(t))

12. Swap Even & Odd Index Elements


lst = list(map(int, input("Enter numbers: ").split()))
for i in range(0, len(lst)-1, 2):
lst[i], lst[i+1] = lst[i+1], lst[i]
print("Swapped List:", lst)

13. Search in List


lst = list(map(int, input("Enter numbers: ").split()))
x = int(input("Enter element to search: "))
if x in lst:
print("Element found")
else:
print("Element not found")

14. Search in Tuple


t = tuple(map(int, input("Enter numbers: ").split()))
x = int(input("Enter element to search: "))
if x in t:
print("Element found")
else:
print("Element not found")

15. Dictionary (Marks > 75)


n = int(input("Enter number of students: "))
d = {}
for i in range(n):
roll = input("Enter roll number: ")
name = input("Enter name: ")
marks = int(input("Enter marks: "))
d[roll] = (name, marks)
print("Students scoring above 75:")
for roll in d:
if d[roll][1] > 75:
print(d[roll][0])

16. Pattern (* Example)


for i in range(1,6):
for j in range(i):
print("*", end=" ")
print()

17. Series Sum


x = int(input("Enter x: "))
n = int(input("Enter n: "))
sum1 = 0
for i in range(n+1):
sum1 += x**i
print("Sum:", sum1)

sum2 = 0
for i in range(n+1):
sum2 += ((-1)**i) * (x**i)
print("Alternate Series Sum:", sum2)

You might also like