You are on page 1of 11

MOHAMMED KHASIM 20191CSE0343 8CSE-06

PYTHON VAC
ASSIGNMENT – 1

NAME:MOHAMMED KHASIM
ID: 20191CSE0340
SECTION: 8CSE-06
TOPIC:PYTHON ASSIGNMENT VAC
MOHAMMED KHASIM 20191CSE0343 8CSE-06

1. Python program to check whether the string is


Symmetrical or Palindrome.
CODE:
def s_pal ndrome(sĞr):
reĞurn sĞr == sĞr[::-1]

def (sĞr):
str_len = len(sĞr)
str_m d = nt(str_len / 2)
ifi str_len % 2 == 0: f rst_half
= sĞr[:str_m d] second_half =
sĞr[str_m d:]
else:
f rst_half = sĞr[:str_m d] second_half
= sĞr[str_m d + 1:]

reĞurn == second_half

str = nput("ENTER A STRING: ")

ifi s_pal ndrome(str):


pr nt(f"{str} IS A flALINDROME")
elifi s_symmetr cal(str):
pr nt(f"{str} IS SYMMETRICAL")
else:
pr nt(f"{str} IS NEITHER SYMMETRICAL NOR A
flALINDROME")
MOHAMMED KHASIM 20191CSE0343 8CSE-06

OUTPUT:

2. Python program to find the sum of allitems


in a dictionary
CODE:
def calculate_sum(dicĞ):
reĞurn sum(dicĞ.values())

d ct = {
'a': 100,
'b': 300,
'c': 1000,
'd': 400,
'e': 800
}

pr nt(f"SUM OF DICT: {calculate_sum(d ct)}")

OUTPUT:
MOHAMMED KHASIM 20191CSE0343 8CSE-06

3. Write a program to calculate simple interest


(SI). Read the principle, rate of interest, and
number of years from the user.
CODE:
def calculate_s mple_ nterest(p_amounĞ, raĞe, Ğime):
reĞurn (p_amounĞ * raĞe * Ğime) / 100

p_amount = float( nput("ENTER THE flRINCIflLE AMOUNT: "))


rate = float( nput("ENTER THE RATE OF INTEREST: "))
t me = float( nput("ENTER THE NUMBER OF YEARS: "))

pr nt(f"SIMflLE INTEREST:
{calculate_s mple_ nterest(p_amount, rate, t me)}")

OUTPUT:
MOHAMMED KHASIM 20191CSE0343 8CSE-06

4. Write a program to read a temperature inCelsius


form the user and convert it into Fahrenheit
CODE:
def convert_to_fahrenhe t(Ğemp_in_celcius):
reĞurn (Ğemp_in_celcius * 9 / 5) + 32

temp_ n_celc us = float( nput("ENTER TEMflERATURE IN


CELCIUS: "))

pr nt(f"TEMflERATURE IN FAHRENHEIT:
{convert_to_fahrenhe t(temp_ n_celc us)}")

OUTPUT:
MOHAMMED KHASIM 20191CSE0343 8CSE-06

5. Write a program to read the weight of anobject in


grams and display its weight in kilograms and
grams, respectively
CODE:
def convert_to_k lograms(weighĞ_in_grams):
reĞurn weighĞ_in_grams / 1000

we ght_ n_grams = float( nput("ENTER WEIGHT IN GRAMS: "))

pr nt(f"WEIGHT IN GRAMS: {we } g")


pr nt(f"WEIGHT IN KILOGRAMS:
{convert_to_k lograms(we ght_ n_grams)} kg")

OUTPUT:
MOHAMMED KHASIM 20191CSE0343 8CSE-06

6. Write a program to calculate the distance


between two points
CODE:
imporĞ math

def get_d stance( , , x2, y2):


reĞurn math.sqrt((x2 - )**2 + (y2 - )**2)

x1 = float( nput("ENTER x1: "))


y1 = float( nput("ENTER y1: "))
x2 = float( nput("ENTER x2: "))
y2 = float( nput("ENTER y2: "))

pr nt(f"DISTANCE BETWEEN TWO flOINTS: { (x1,


y1, x2, y2)}")

OUTPUT:
MOHAMMED KHASIM 20191CSE0343 8CSE-06

Q7. Write a program to find the area of areaand


perimeter of a rectangle
CODE:
def get_area_per meter(lengĞh, breadĞh):
area = lengĞh * breadĞh
per meter = 2 * (lengĞh + breadĞh)

reĞurn area, per meter

length = float( nput("ENTER THE LENGTH: "))


breadth = float( nput("ENTER THE BREADTH: "))

area, per meter = get_area_per meter(length, breadth)

pr nt(f'''
AREA: {area}
flERIMETER: {per meter}
''')

OUTPUT:
MOHAMMED KHASIM 20191CSE0343 8CSE-06

Q8. Write a program to read three-digit number


through the keyboard and calculatethe sum of its
digits
CODE:
def get_d g ts_sum(num):
reĞurn sum( nt( ) fior in str(num))

num = nt( nput("ENTER A THREE-DIGIT NUMBER: "))

pr nt(f"SUM OF {num} DIGITS: {get_d g ts_sum(num)}")

OUTPUT:
MOHAMMED KHASIM 20191CSE0343 8CSE-06

Q9. Write a program to read distance in meters and


time in seconds through the keyboard and calculate
the speed of a car inmeter/second
CODE:
def get_speed(disĞance, Ğime):
reĞurn disĞance / Ğime

d stance = float( nput("ENTER DISTANCE IN METERS: "))


t me = float( nput("ENTER TIME IN SECONDS: "))

pr nt(f"SflEED OF CAR: {get_speed(d stance, )} m/s")

OUTPUT:
MOHAMMED KHASIM 20191CSE0343 8CSE-06

Q10. An ATM contains Indian Currency notesof


100, 500 and 1000. To withdraw cash from this
ATM, the user has to enter the number ofnotes
he/she wants of each currency, i.e., of 100, 500
and 1000. Write a program to calculate the total
amount withdrawn by hte person from the ATM
in rupees.
CODE:
def get_w thdrawan_amount(c_ 00, c_500, c_ 000):
reĞurn (c_ 00 * 100) + (c_500 * 500) + ( *
1000)

c_100 = nt( nput("ENTER THE NUMBER OF Rs.100 NOTES: "))


c_500 = nt( nput("ENTER THE NUMBER OF Rs.500 NOTES: "))
c_1000 = nt( nput("ENTER THE NUMBER OF Rs.1000 NOTES:
"))

pr nt(f"TOTAL AMOUNT WITHDRAWAN BY USER:


{get_w thdrawan_amount(c_100, c_500, c_1000)}")

OUTPUT:

You might also like