DIP lab 1
DIP lab 1
Semester:
Objectives
Lab Conduct
if condition:
statement_1
else:
statement_2
Lab Task 2
Create a list with the sequence 1, 2, 3… 20. Then using the slice operation
(:) on this list, print the following sub-lists:
5, 6, 7… 20
1, 2, 3… 12
7, 8, 9 … 16
4, 5
11, 12, 13, 14
### TASK 2 CODE STARTS HERE ###
Lab Task 3
Write a function that takes 2 lists as arguments. Both the lists must be of
the same length. The function should calculate the product of the
corresponding items and place them in a third list. You must NOT use the
product operator (*). You need to provide the function definition and the
function call in the code. (Hint: You need to make use of loops in your
function.) The function definition syntax is given as follows:
def function_name:
statement_1
…
return output
Lab Task 5
In this task, you will focus on file handling. Write code that first creates a
text file “lab2.txt” with the message “My name is <your_name>”. Then,
your code must open the file in read mode and display the contents of the
text file. Next, the file must be opened in append mode and the message
“My registration number is <reg_number>” must be added to the text file.
Finally, the file is read again to display the modified contents.