Module 2 Data Types, Operators, Variables Assignment
Module 2 Data Types, Operators, Variables 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..
a. Create another list by concatenating above 2 lists
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)
a. Find the common elements in above 2 Sets.
b. Find the elements that are not common.
c. Remove element 7 from both the Sets.
3. Create 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.
b. Update another country and its covid-19 cases in the dictionary.
Operators
Please implement by using Python
A. a/=b
B. c*=5
3. A. How to check the presence of an alphabet ‘S’ in the word “Data Science” .
b. frequency = {}
for element in concatenated_list:
if element in frequency:
frequency[element] += 1
else:
frequency[element] = 1
c. reverse_list =List3[::-1]
b. not_common_elements = set1.symmetric_difference(set2)
c. set1.discard(7)
set2.discard(7)
print("Set 1 after removing 7:", set1)
print("Set 2 after removing 7:", set2)
b. covid_cases["State6"] = 50000
print(covid_cases)
Operators
1. a. To write an equation that relates 399, 543, and 12345, we can use the concept of arithmetic
operations such as addition, subtraction, multiplication, and division. Here's one possible equation:
(399×3)+543=12345
This equation states that if we multiply 399 by 3 and then add 543 to the result, we get 12345.
In Python, when you perform integer division (using the // operator) between two positive
integers, the result is the largest integer that is less than or equal to the true mathematical
result of the division.
However, when you perform integer division with a negative numerator (like -5), the result
is the smallest integer greater than or equal to the true mathematical result of the division.
This behavior ensures that the result of integer division maintains the properties of floor
and ceiling functions, which are common mathematical operations.
2. a=a/b
so a=1.6667
and,
c=c*5
if 'S' in word:
else:
((4*4)*(4-3)) =64
Variables
Variable names must begin with a letter (a-z, A-Z) or an underscore (_).
The remaining characters in the variable name can be letters (a-z, A-Z), digits (0-9), or underscores
(_). Variable names are case-sensitive.
a. Age1 = 5
This variable name is valid because it starts with a letter ('A') and is followed by letters and a digit.
b. 5age = 55
This variable name is invalid because it starts with a digit ('5'). Variable names cannot start with a
digit; they must start with a letter or an underscore.
2. Age_1 = 100
This variable name is valid because it starts with a letter ('A') and is followed by letters, a digit, and an
underscore.
age@1 = 100
This variable name is invalid because it contains a special character ('@'). Variable names cannot contain
special characters other than underscores (_)