Module 2 Data Types, Operators, Variables Assignment
Module 2 Data Types, Operators, Variables Assignment
"""
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]
print(List_A)
print(List_B)
frequency = {}
if item in frequency:
frequency[item] += 1
else:
frequency[item] = 1
print(" frequency of each element in the concatenated list.")
print(frequency)
print(List_C)
print("list in reverse order is:")
print(Reverse(List_C))
SetB = set([5,6,7,8,9,10,11,12,13,14,15])
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())
#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. 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” .
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'")
results = (4**3)
print (results)
#Variables
#Please implement by using Python
#1. What will be the output of the following (can/cannot):