[go: up one dir, main page]

0% found this document useful (0 votes)
18 views19 pages

Python Avi 2 5

Python

Uploaded by

avimane0510
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)
18 views19 pages

Python Avi 2 5

Python

Uploaded by

avimane0510
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/ 19

Experiment no:2

ADDITION Program Statement:

Write a python program to take the three entities of str, int and float datatype
from user and demonstrate the operation for following python inbuilt
functions of two numbers

PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
# Taking input from the user
str_value = input("Enter a string: ")
int_value = int(input("Enter an integer: "))
float_value = float(input("Enter a float: "))

# print function
print("String value:", str_value)
print("Integer value:", int_value)
print("Float value:", float_value)

# type function
print("Type of str_value:", type(str_value))
print("Type of int_value:", type(int_value))
print("Type of float_value:", type(float_value))

# id function
print("ID of str_value:", id(str_value))
print("ID of int_value:", id(int_value))
print("ID of float_value:", id(float_value))

# len function for the string


print("Length of str_value:", len(str_value))
# eval function
expression = input("Enter a mathematical expression : ")
result = eval(expression)
print("Result of evaluated expression:", result)
# typecasting
new_int = float(int_value)
new_float = int(float_value)
print("Typecasted int to float:", new_int)
print("Typecasted float to int:", new_float)

OUTPUT:-
EXPERIMENT NO:-03
• Program Statement:

a. Write a program to perform different Arithmetic Operations on


numbers in Python.
Program:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

addition = num1 + num2

subtraction = num1 - num2

multiplication = num1 * num2

division = num1 / num2

modulus = num1 % num2

exponentiation = num1 ** num2

floor_division = num1 // num2

print("Addition:", addition)

print("Subtraction:", subtraction)

print("Multiplication:", multiplication)

print("Division:", division)

print("Modulus:", modulus)

print("Exponentiation:", exponentiation)

print("Floor Division:", floor_division)

OUTPUT:-
b. Write a program to perform different Logical Operations on
numbers in Python.
Program:-

#NAME :- MANE AVISHKAR SANJAY


#PRN NO:-22UET062

num1 = int(input("Enter first number: "))


num2 = int(input("Enter second number: "))
and_operation = num1 and num2
or_operation = num1 or num2
not_operation_num1 = not num1
not_operation_num2 = not num2
print("AND Operation:", and_operation)
print("OR Operation:", or_operation)
print("NOT Operation on first number:", not_operation_num1)
print("NOT Operation on second number:", not_operation_num2)

OUTPUT:-
c.Write a program to perform different Assignment
Operations on numbers in Python.
PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062

n1=int(input("Enter the first number: "))


n2=int(input("Enter the second number: "))
n1 += n2
print("The Addition is :", n1)
n1 -= n2
print("The substraction is :", n1)
n1 *= n2
print("The Multiplication is :",n1)
n1 /= n2
print("The Division is:", n1)
n1 %= n2
print("The modulus is:", n1)
n1 //=n2
print("The Floor devision is :", n1)
n1 **=n2
print("The Exponent is :",n1)

OUTPUT:
d.Write a program to perform different Membership
Operations on numbers in Python.
PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
num1 = [10, 20, 30, 40, 50]
num = int(input("Enter a number: "))
print("PRESENT NO. IS : ",num1)
if num in num1:
print(num,"The number is present ")
if num not in num1:
print("The number is not present")

OUTPUT:-
e.Write a program to perform different Identity Operations on
numbers in Python.
PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET06
A = int(input("Enter value of A : "))
B = int(input("Enter value of B : "))
if A is B:
print("A and B are same:")
if A is not B:
print("A and b are not same:")

OUTPUT:-
EXPERIMENT NO:-04

PROGRAM STATEMENT:
A)Write a Python program to sum of two given integers. However, if the sum is
between 15 to 20, display the result on output console. [Use if…. Statement]
PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
a = int(input("Enter first integer: "))
b = int(input("Enter second integer: "))
sum_1 = a + b
if 15 <= sum_1 <= 20:
print("The sum is:", sum_1)
else :
print("sum is not between 15 to 20")

OUTPUT:-
PROGRAM STATEMENT:
B)Write a Python program to accept two integer numbers from user. Find the
largest number from two integer values and display the result on output
console.[Use if...else statement]
PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
X = int(input("Enter first integer: "))
Y = int(input("Enter second integer: "))
if X > Y:
print("The largest number is:", X)
else:
print("The largest number is:", Y)

OUTPUT:-

PROGRAM STATEMENT :
C) Write a Python program to accept marks of three subjects in the range of 0 to 100. If the
marks in all three subjects are greater than 40 then calculate the percentage. Assign the
appropriate grade as per following
a. For percentage greater than or equal to 75, assign “Outstanding”.
b. For percentage is greater than or equal to 70 to less than 75, assign “Distinction Grade”.
c. For percentage is greater than or equal to 60 to less than 70, assign “A Grade”.
d. For percentage is greater than or equal to 50 to less than 60, assign “B Grade”.
e. For percentage is greater than or equal to 40 to less than 50, assign “C Grade”

PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
subject1 = int(input("Enter marks for subject 1: "))
subject2 = int(input("Enter marks for subject 2: "))
subject3 = int(input("Enter marks for subject 3: "))
if subject1 > 40 and subject2 > 40 and subject3 > 40:
total_marks = subject1 + subject2 + subject3
percentage = total_marks / 3
if percentage >= 75:
grade = "Outstanding"
elif percentage >= 70:
grade = "Distinction Grade"
elif percentage >= 60:
grade = "A Grade"
elif percentage >= 50:
grade = "B Grade"
elif percentage >= 40:
grade = "C Grade"
else:
grade = "Fail"
print(f"Percentage: {percentage:.2f}%")
print(f"Grade: {grade}")
else:
print("Marks in all subjects must be greater than 40 to calculate the
percentage.")

OUTPUT:-

PROGRAM STATEMENT:

D) Write a Python program to find whether a given number (accept from the
user) is even or odd, print out an appropriate message to the user. [ use
ternary operator]
PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
number = int(input("Enter a number: "))
if number % 2==0 :
print("Enterd Number is even")
else :
print("Enterd number is odd")

OUTPUT:

EXPERIMENT NO:-05
A)Write a Python program to find whether a given number (accept from the
user) is Palindrome or not Palindrome number. Print out an appropriate
message to the user. [Use while…. Statement]
PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
num = int(input("Enter a number: "))
num2 = num
num3 = 0
while num > 0:
digit = num % 10
num3 = num3 * 10 + digit
num = num // 10
if num2 == num3:
print("Enterd number is a Palindrome Number.")
else:
print("Enterd number is not a Palindrome Number.")

OUTPUT:-

B)Write a Python program to find whether a given number (accept from the
user) is Armstrong number or not Armstrong number. Print out an appropriate
message to the user. [Use while…. Statement]

PROGRAM :-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
num = int(input("Enter a number: "))
num2 = num
result = 0
n = len(str(num))
while num > 0:
digit = num % 10
result += digit ** n
num = num // 10
if num2 == result:
print("Enterd number is an Armstrong number.")
else:
print("Enterd number is not an Armstrong number.")

OUTPUT:-

C)Write a Python program to find whether a given number (accept from the
user) is prime or note prime number. Print out an appropriate message to the
user. [Use for…. Statement]

PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
number = int(input("Enter a number: "))
prime = True
if number <= 1:
prime = False
else:
for i in range(2, number):
if number % i == 0:
prime = False
break
if prime:
print("Enterd number is a prime number.")
else:
print("Enterd number is not a prime number.")

OUTPUT:-

D)Write a python program to print the following patterns on output console


PROGRAM :-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
N = int(input("Enter the number : "))
for i in range(1,N+1):
print("*"*i,end="")
print()

OUTPUT:-

PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
N = int(input("Enter the number : "))
for i in range(N,0,-1):
print("*"*i,end="")
print()

OUTPUT:-

PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
N = int(input("Enter the number : "))
for i in range(N, 0, -1):
print('*' * i)
print("\n")

OUTPUT:-

PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
N = int(input("Enter the number : "))
for i in range(1, N+1):
print(str(i) * i)
print("\n")

OUTPUT:-

PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
N = int(input("Enter the number : "))
for i in range(1, N+1):
for j in range(1, i + 1):
print(j, end="")
print()
print("\n")
OUTPUT:-

PROGRAM:-
#NAME :- MANE AVISHKAR SANJAY
#PRN NO:-22UET062
N = int(input("Enter the number : "))
for i in range(1, N, 2):
print(' ' * ((N - i) // 2) + '*' * i)
print("\n")

OUTPUT:-

You might also like