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

Python Practical Solutions Guide

The document contains practical Python solutions for various programming problems, including a simple calculator, factorial calculation, sum of natural numbers, simple interest calculation, and number swapping. It also includes algorithms for finding the largest of three numbers, generating a Fibonacci series, checking for prime numbers, finding the largest in a list, searching in a list, and adding two lists. Additionally, it covers NumPy operations for mean, median, mode, 2D array manipulations, and visualizations using line charts and bar graphs.

Uploaded by

arsh48260
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)
5 views3 pages

Python Practical Solutions Guide

The document contains practical Python solutions for various programming problems, including a simple calculator, factorial calculation, sum of natural numbers, simple interest calculation, and number swapping. It also includes algorithms for finding the largest of three numbers, generating a Fibonacci series, checking for prime numbers, finding the largest in a list, searching in a list, and adding two lists. Additionally, it covers NumPy operations for mean, median, mode, 2D array manipulations, and visualizations using line charts and bar graphs.

Uploaded by

arsh48260
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 – SOLUTIONS

Q1. Simple Calculator


num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operator = input("Enter operation (+, -, *, /): ")

if operator == '+':
print(num1 + num2)
elif operator == '-':
print(num1 - num2)
elif operator == '*':
print(num1 * num2)
elif operator == '/':
print(num1 / num2)
else:
print("Invalid operator")

Q2. Factorial Program


num = int(input("Enter a number: "))
factorial = 1
for i in range(1, num + 1):
factorial *= i
print(factorial)

Q3. Sum of Natural Numbers


num = int(input("Enter number: "))
total = 0
for i in range(1, num + 1):
total += i
print(total)

Q4. Simple Interest


P = float(input("Enter principal: "))
R = float(input("Enter rate: "))
T = float(input("Enter time: "))
SI = (P * R * T) / 100
print(SI)

Q5. Swapping Numbers


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

Q6. Largest of Three Numbers


a=int(input("A"))
b=int(input("B"))
c=int(input("C"))
if a>=b and a>=c:
largest=a
elif b>=a and b>=c:
largest=b
else:
largest=c
print(largest)

Q7. Fibonacci Series


n=int(input("Enter terms"))
a=0
b=1
print(a, b, end=" ")
for i in range(2, n):
c=a+b
print(c, end=" ")
a=b
b=c

Q8. Prime Number


a=int(input("Enter number"))
if a>1:
for i in range(2, a):
if a%i==0:
print("Not Prime")
break
else:
print("Prime")
else:
print("Not Prime")

Q9. Largest in List


a=[]
n=int(input("Enter elements"))
for i in range(n):
[Link](int(input()))
largest=a[0]
for i in a:
if i>largest:
largest=i
print(largest)

Q10. Search in List


a=[12,4,10,9,7]
element=int(input("Search"))
for i in range(len(a)):
if element==a[i]:
print("Found at index", i)
break
else:
print("Not Found")

Q11. Add Two Lists


list1=[1,2,3]
list2=[4,5,6]
new=[]
for i in range(len(list1)):
[Link](list1[i]+list2[i])
print(new)

Q12. NumPy Mean, Median, Mode


import numpy as np
a=[1,2,2,4,5,6]
print([Link](a))
print([Link](a))
values,counts=[Link](a,return_counts=True)
print(values[[Link](counts)])

Q13. 2D Array
import numpy as np
arr=[Link]([[1,2],[3,4]])
print(arr*2)
print([Link]())
print([Link](axis=1))
print([Link](axis=0))
print([Link], [Link])

Q14. Line Chart


import [Link] as plt
x=[1,2,3]
y=[4,5,6]
[Link](x,y)
[Link]("X axis")
[Link]("Y axis")
[Link]("Line Chart")
[Link]()

Q15. Bar Graph


import [Link] as plt
books=["Python","Java"]
popularity=[10,15]
[Link](books,popularity,color="orange")
[Link]("Favourite Books")
[Link]("Books")
[Link]("Popularity")
[Link]()

You might also like