0% found this document useful (0 votes)
29 views9 pages

Py 48 1 and 2

The document contains summaries of 8 Python programs: 1. Programs to print "Hello World", swap variables using a third variable and without a third variable, find the square root of a positive number, and calculate the area of a rectangle and circle. 2. Programs to check if a number is even or odd, positive, negative or zero, find the roots of a quadratic equation, and check if a character is a vowel or consonant. 3. Programs to find the maximum of three numbers, calculate employee salary based on degree and experience, and check if an input is a character, digit or special symbol.

Uploaded by

Nimisha
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)
29 views9 pages

Py 48 1 and 2

The document contains summaries of 8 Python programs: 1. Programs to print "Hello World", swap variables using a third variable and without a third variable, find the square root of a positive number, and calculate the area of a rectangle and circle. 2. Programs to check if a number is even or odd, positive, negative or zero, find the roots of a quadratic equation, and check if a character is a vowel or consonant. 3. Programs to find the maximum of three numbers, calculate employee salary based on degree and experience, and check if an input is a character, digit or special symbol.

Uploaded by

Nimisha
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
You are on page 1/ 9

21BECE30048

Practical Set -1

Practical 1.1 : Write a Python program to print “Hello World”.

Code:

print ("Hello World")

Output:

Hello World

Practical 1.2 : Write a Python program to swap two variables using third
variable.

Code:

X=1
0
Y=18
Z=X
X=Y
Y=Z
print ("The value of X after swapping is:", X)
print ("The value of Y after swapping is:", Y)

Output:

The value of X after swapping is: 18


The value of Y after swapping is: 10
21BECE30048

Practical 1.3 : Write a Python program to swap two variables without third
variable.

Code:

X = 10
Y = 18
X=X+Y
Y=X-Y
X=X-Y
print ("The value of X after swapping is :", X)
print ("The value of Y after swapping is :", Y)

Output:

The value of X after swapping is: 18


The value of Y after swapping is: 10

Practical 1.4 : Write a Python program to find square root of positive number.

Code:

A = float(input("Enter the value that you want to find Square root : "))
sqrt = A**0.5
print ("The value of Square root is :", sqrt)

Output:

Enter the value that you want to find Square root : 4


The value of Square root is : 2
21BECE30048

Practical 1.5 : Write a Python program to find area of a rectangle and circle.

Code:

L = float(input("Enter the length of Rectangle : ")) B


= float(input("Enter the breadth of Rectangle : "))

R = L*B
print("Area of Rectangle is :", R)
r = float(input("\nEnter the radius of circle : "))
C = 3.14*r*r
print("Area of circle is : ", C)

Output:

Enter the length of Rectangle : 10


Enter the breadth of Rectangle :5
Area of Rectangle is : 50

Enter the radius of circle :10


Area of circle is : 314

Practical 1.6 : Write a Python program to find sum of n natural numbers without
loop.

Code:

n = float(input("Enter the value of n :"))


n = n*(n+1)/2
print ("\nSum of n natural number is :", n)

Output:

Enter the value of n : 10


Sum of n natural number is : 55
21BECE30048

Practical 1.7 : Write a Python program to check various arithmetic operators of


Python.

Code:

A = float(input("Enter the value of A : "))


B = float(input("Enter the value of B : "))
print('x + y =', A + B)
print('x - y =', A - B)
print('x * y =', A * B)
print('x / y =', A / B)
print('x % y =', A % B)
print('x ** y =', A**B)
print('x // y =', A //B)

Output:

Enter the value of A :


10.0 Enter the value of B :
2.0 x + y = 12
x-y=8
x * y = 20
x/y=5x
%y=0
x ** y = 100
x // y = 5

Practical 1.8 : Write a Python program to check output of modulo operator.

Code:

A = float(input("Enter the value of A : "))


B = float(input("Enter the value of B : "))
print('x % y =', A % B)

Output:
Enter the value of A : 13
Enter the value of B : 5
x % y = 3.0
21BECE30048

Practical Set -2

Practical 2.1 : Write a Python program to check whether the entered number
is even or odd.

Code:

a = int(input("Enter number : "))


if a % 2 == 0:
print(a, "is a Even Number")
else:
print(a, "is a Odd Number")

Output:

Enter number : 6
6 is a Even Number

Practical 2.2 : Write a Python program to find whether entered number is


positive, negative or zero.

Code:

a = int(input("Enter number : "))


if a < 0 :
print(a, "is a Negative Number")
elif a == 0 :
print(a, "Number is Zero")
else:
print(a, "is a Positive Number ")

Output:

Enter number : 6
6 is a Positive Number
21BECE30048

Practical 2.3 : Write a Python program to find roots of quadratic equations if


roots are real.
Code:
def root(a, b, c):
d = b ** 2 - 4 * a * c
sqrt_d = abs(d) ** 0.5
if d > 0:
print("Quadratic equation has real and distinct roots")
print((-b + sqrt_d) / (2 * a))
print((-b - sqrt_d) / (2 * a))
if d == 0:
print("Quadratic equation has real and one roots")
print(-b / (2 * a))
if d < 0:
print("Quadratic equation has imaginary and distinct roots")
print(-b / (2 * a), "+ i", sqrt_d / (2 * a))
print(-b / (2 * a), "- i", sqrt_d / (2 * a))
p = int(input("Enter number a: "))
q = int(input("Enter number b: "))
r = int(input("Enter number c: "))
if p == 0:
print("Enter correct quadratic equation.")
else:
root(p, q, r)

Output:
Enter number a:2
Enter number b:-7
Enter number c:3
Quadratic equation has real and one roots
3.0
0.5
21BECE30048

Practical 2.4 : Write a Python program to check whether entered character is


vowel or consonant.

Code:

a = input("Enter character : ")


if ((a == 'a') | (a == 'e') | (a == 'i') | (a == 'o') | (a == 'u') | (a == 'A') | (a == 'E') | (a == 'I') |
(a == 'O') | (a == 'U')):
print("It is Vowel")
else:
print("It is Consonant")

Output:

Enter character: a
It is Vowel

Practical 2.5 : Write a Python program to find maximum of three numbers


(nested if-else).

Code:

a = int(input("Enter Number1: "))


b = int(input("Enter Number2: "))
c = int(input("Enter Number3: "))
if a > b:
if a > c:
print(a, "is maximum")
elif c > b:
print(c, "is maximum")
elif b > c:
print(b, "is maximum")
else:
print(c, "is maximum")

Output:

Enter Number1: 2
Enter Number2: 5
Enter Number3: 3
5 is maximum
21BECE30048

Practical 2.6 : Write a Python program to calculate the salary of an employee


based on following conditions

# (nested if-else):
# 1. if degree = B.E. and experience < 5 years, salary=30000
# 2. if degree = B.E. and experience >= 5 years, salary=40000
# 3. if degree = M.E. and experience < 5 years, salary=50000
# 4. if degree = M.E. and experience >= 5 years, salary= 60000

Code:

degree = input("Enter Degree(ME or BE) : ")


exp = int(input("Enter Experience(years) : "))
if degree == 'BE':
if exp < 5:
print("salary will be 30000")
elif exp >= 5:
print("salary will be 40000")
elif degree == 'ME':
if exp < 5:
print("salary will be 50000")
elif exp >= 5:
print("salary will be 60000")
else: print("Enter valid Degree.")

Output:

Enter Degree(ME or BE) : ME


Enter Experience(years) : 6
salary will be 6000
21BECE30048

Practical 2.7 : Write a Python program to check whether entered input is


character, digit or special symbol using ladder if-else.
Code:

a = input("Enter : ")
if a.isalpha():
print(a, "is a Character")
elif a.isnumeric():
print(a, "is a Number")
else:
print(a, "is a Special Symbol")

Output:

Enter : A
A is a Character

You might also like