Professional Documents
Culture Documents
Solution: Distance can be calculated using the two points (x1, y1) and (x2, y2), the distance d between these points is
given by the formula:
for e.g: let (x1, y1) = (10,9) and (x2, y2) = (4, 1)
then (x2 - x1)2 = (10 - 4)2 = 62 = 36 and
(y2 - y1)2 = (9 - 1)2 = 82 = 64 now 64 + 36 = 100 and
100 is square root of 10
Therefore, the distance between (10, 9) and (4 ,1) is 10
4. Write a program to demonstrate branching statements in python.
5. Write a program to demonstrate list and tuple, set and dictionary in python.
List is a non-
Tuple is also a non- Set data structure is
homogeneous data Dictionary is also a
homogeneous data also non-
structure which stores non-homogeneous data
structure which stores homogeneous data
the elements in single structure which stores
single row and multiple structure but stores in
row and multiple rows key value pairs
rows and columns single row
and columns
List can be represented Tuple can be represented Set can be represented Dictionary can be
by [ ] by ( ) by { } represented by {:}
List can use nested Tuple can use nested Set can use nested Dictionary can use
among all among all among all nested among all
Dictionary can be
List can be created Tuple can be created Set can be created
created
using list() function using tuple() function. using set() function
using dict() function.
Set is mutable i.e we
List is mutable i.e we Tuple is immutable i.e we Dictionary is mutable.
can make any changes
can make any changes can not make any changes But Keys are not
in set. But elements
in list. in tuple duplicated.
are not duplicated.
Strftime() method
➢ The strftime() method returns a string representing date and time using date, time or datetime object.
➢ The program below converts a datetime object containing current date and time to different string
formats.
➢ In the above program, %Y, %m, %d etc. are format codes. The strftime() method takes one or more
format codes as an argument and returns a formatted string based on it.
How it works?
Step1: We imported datetime class from the datetime module. It's because the object of datetime class
can access strftime() method.
Step2: The datetime object containing current date and time is stored in now variable.
Step3: The strftime() method can be used to create formatted strings.
Step4: The string you pass to the strftime() method may contain more than one format codes.
Step1: Create a text file with any contents of your choice. (Filename: MyTextFile.txt)
Step2: Create Python file and type the following code. (Filename: TextFileAnalysis.py)
Step 3: Run the file from command prompt and explore all the options.
Note: The values can also contain decimal values, but make sure the total value should be 100.