# -*- coding: utf-8 -*-
"""
Created on Tue Sep 17 10:52:01 2024
@author: Admin
"""
import pandas as Pd
import numpy as nm
# list with mixed data types with : integer, float, string, complex and Boolean
List_A = [8,29,88.33,89.523, "Good Morning ","Everyone "," All the Best for the
Day",3+5j,7+6j,True,False]
List_B = [59,3,15.86,1598.24, "My","Name","Ariana Prashant
Dasi",6+92j,13+65j,False,True]
print(List_A)
print(List_B)
# a. Create another list by concatenating above 2 lists
List_C = List_A + List_B
print("concatenated list for above two lists is:")
print(List_C) #printing concatenated list3
#b. Find the frequency of each element in the concatenated list.
frequency = {}
# iterating over the list
for item in List_C:
if item in frequency:
# incrementing the counr
frequency[item] += 1
else:
frequency[item] = 1
print(" frequency of each element in the concatenated list.")
print(frequency)
# c. Print the list in reverse order.
print(List_C)
print("list in reverse order is:")
print(Reverse(List_C))
# 2. Create 2 Sets containing integers (numbers from 1 to 10 in one set and 5 to
15 in other set)
SetA = set([1, 2, 3, 4, 5, 6,7, 8, 9, 10])
SetB = set([5,6,7,8,9,10,11,12,13,14,15])
#a. Find the common elements in above 2 Sets.
print("\n common elements in above 2 Sets are:", end = " ")
common = SetA.intersection(SetB)
print(common)
#b. Find the elements that are not common.
print("\n elements that are not common in above two sets are:", end = " ")
notcommon = SetA.difference(SetB)
print(notcommon)
#c. Remove element 7 from both the Sets.
SetA.remove(7)
print(SetA)
SetB.remove(7)
print(SetB)
# Creating a data dictionary of 5 states having state name as key and number of
covid-19 cases as values.
# a. Print only state names from the dictionary.
Dict =
{'Mumbai':15478,'Andhrapradesh':48975,'Gujarath':25896,'Bhiar':5895,'Jammu':1598}
print("\n data of dictionary of 5 states having state name as key and number of
covid-19 cases as values.:", end = " ")
print(Dict)
print("\n ", end = " ")
print(Dict.keys())
# b. Update another country and its covid-19 cases in the dictionary.
Dict2 = {'India':1895478,'USA':789413,'France':15987,'UK':159875}
print("Original Dictionary:")
print(Dict2)
Dict2.update(India='258975', UK='1587452')
print("Dictionary after updation:")
print(Dict2)
#operation
# 1.A. Write an equation which relates 399, 543 and 12345
Y = 543
X = 12345
Q = X // Y
R = X % Y
print (Q)
print (R)
if Q == 22 & R == 399:
print (f"{X} = {Y} * {Q} + {R}")
else:
print (f"{X} cannot be divided by {Y} to produce a quotient of 22 and a
reminder is 399")
# 1.B. “When I divide 5 with 3, I get 1. But when I divide -5 with 3, I get -2”—
How would you justify it?
a = 5
b = 3
c = -5
print("\n When I divide 5 with 3 we get :", end = " ")
d = a / b
print(d)
print("\n when I divide -5 with 3 we get :", end = " ")
e = c / b
print(e)
# 2. a=5,b=3,c=10.. What will be the output of the following
a = 5
b = 3
c = 10
#2.A. a/=b
a /= b
print (a)
# 2. B. c*=5
c *= 5
print(c)
#3. A. How to check the presence of an alphabet ‘S’ in the word “Data Science” .
test = 'Data Science'
if 's' in test:
print ("Text contains the word 's'")
else:
print ("Text doesnt have word 's'")
if 'S' in test:
print ("Value contains the word 'S'")
else:
print ("Value doesnt have word 'S'")
#3.B. How can you obtain 64 by using numbers 4 and 3 .
results = (4**3)
print (results)
#Variables
#Please implement by using Python
#1. What will be the output of the following (can/cannot):
Age1=5 # this will excute
5age=55 # this cannot execute as it has started variable with number
#2. What will be the output of following (can/cannot):
Age_1=100 # this will store the value
age@1=100 # this wont store value as it has special charater only '_' is allowed in
python
# 3. How can you delete variables in Python ?
name_1='Prashant Kumar dasi'
print (name_1)
del name_1
print(name_1)