0% found this document useful (0 votes)
3 views

Module 2 Data Types, Operators, Variables Assignment

Uploaded by

paluruanjana
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Module 2 Data Types, Operators, Variables Assignment

Uploaded by

paluruanjana
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

module – 2 assignment

data types
please implement it by using python.

1. construct 2 lists containing all the available data types (integer, float, string, complex and
boolean) and do the following..
list1 : [ 1, 0.9, “ string”, 3+4j, “ture”]
list2 : [ 2, 1.5, “ anjana”, 4+5r, “flase”]
a. create another list by concatenating above 2 lists
list3 = list1+list2
print(list3)
o/p = [ 1, 0.9, “ string”, 3+4j, “ture”, 2, 1.5, “ anjana”, 4+5r, “flase”]

b. find the frequency of each element in the concatenated list.


c. print the list in reverse order.

2. create 2 sets containing integers (numbers from 1 to 10 in one set and 5 to 15 in other set)
set1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
set2 = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
print(set1)
print(set2)
a. find the common elements in above 2 sets.
set3 = set1 & set2
print(set3)
o/p = {5,6,7,8,9,10}
b. find the elements that are not common.
set4 = set1 | set 2
print(set4)
o/p = { 1,2,3,4,11,12,13,14,15}
c. remove element 7 from both the sets.
set1.discard[7]
set2.discard[7]
print(set1)
print(set2)
o/p =
{ 1, 2, 3, 4, 5, 6, 8, 9, 10}

© 360DigiTMG. All Rights Reserved.


{5, 6, 8, 9, 10, 11, 12, 13, 14, 15}

3. create a data dictionary of 5 states having state name as key and number of covid-19 cases as
values.

state_covid = {
“andhra” = 1234
“tamil nadu” = 5678
“goa” =2345
“karnataka” = 4567
“kerala ”=6789
}
print(state_covid)
o/p = { “andhra” = 1234, “tamil nadu” = 5678, “goa” =2345, “karnataka” = 4567,
“kerala ”=6789}

a. print only state names from the dictionary.


for states in state_cases
print(states)
b. update another country and its covid-19 cases in the dictionary.

state_covid[andhra] = 2345

print(state_covid)

o/p = { “andhra” = 2345, “tamil nadu” = 5678, “goa” =2345, “karnataka” = 4567,
“kerala ”=6789}

operators
please implement by using python

© 360DigiTMG. All Rights Reserved.


1. a. write an equation which relates 399, 543 and 12345
x = 12345
y = 543
z = 399
equation = 22*y + z

if equation == x:
print('it is a valid relation')

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 (a//b) #integer division

print(c//b) #remainder

-2

2. a=5,b=3,c=10.. what will be the output of the following:

a/=b

print(a)

0/p = 1.666666666667

c*=5

print(c)

0/p = 50

© 360DigiTMG. All Rights Reserved.


2. a. how to check the presence of an alphabet ‘s’ in the word “data science” .

“s” in “data science”

c. how can you obtain 64 by using numbers 4 and 3 .


a=4
b=3

c = a**b

print(c)

variables
please implement by using python

1. what will be the output of the following (can/cannot):

a. age1=5
print(age1)
o/p = 5

b. 5age=55
print(5age)
o/p = syntax error

2. what will be the output of following (can/cannot):


a. age_1=100
print(age_1)
o/p = 100
b. age@1=100
print(age@1)
o/p = error

© 360DigiTMG. All Rights Reserved.


3. how can you delete variables in python ?

a = 124

del a

© 360DigiTMG. All Rights Reserved.

You might also like