Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Data Analysis and Visualization

Assignment 02

General Instruction:
1. Write a detailed logic/algorithm for solving each of the questions on A4 sheets.
2. Use unruled A4 sheets, and don’t use the ruled papers from notebooks.
3. The source code of all the programs should be submitted as py files with names
Q1.py, Q2.py, etc for quick reference. Put all files in a folder and submit them as a
single zip file.
4. Scan the A4 sheets and submit them as a PDF file, and handover the hardcopy.
5. Do not plagiarise or copy the source code from the internet or from others.
6. Stick to the assignment deadlines. Total: 35 Marks

Q1. Generate a list of positive integers within a specific range of values. Find the numbers from this
list which are divisible by 7 and 8 and store them in a separate list using List Comprehension. Print
the new list which contains the numbers divisible by 7 and 8.
[5 Marks]

Q2. Write a program to insert a given string before every number present in a list using List
Comprehension. Assume the list and string is hardcoded into the program.

Sample list: [1,2,3,4], string : emp

Output: [‘emp1’, ‘emp2’, ‘emp3’, ‘emp4’]


[5 Marks]

Q3. Read an integer from the user and check whether the number is a palindrome. Write both
iterative and recursive versions to solve this problem.
[5 Marks]

Q4. Read a string and check if the first character is occurring more than once in the string. If yes,
replace the occurrence by ‘$’ from the second instance.

○ Eg: input: restart, output : resta$t


[5 Marks]
Q5. Read a string from the user, assuming it is a password creation process. When the user sets a
password, the following conditions should be satisfied:

a) At least one lowercase alphabet is required


b) At least one uppercase alphabet is required
c) At least one digit is required
d) At least one special character is required
e) The length of the string should be at least 8 and maximum 16

1. If the password entered does not satisfy the above conditions, then throw out the
appropriate message.
2. If the password entered contains four occurrences of conditions a) to d), then print that the
password strength is strong.
3. If the password entered contains two or three occurrences of conditions a) to d), then print
that the password strength is medium.
4. If the password entered contains only one occurrence of d), then print that the password
strength is poor.
[15 Marks]

Note:
● Refer to the documentation for string methods and use relevant methods in your programs
which require string operations.
● Here is the recommended reference:
https://python-reference.readthedocs.io/en/latest/docs/str/
● You can also use other references.

You might also like