0% found this document useful (0 votes)
4 views3 pages

NIET Python PracticeSet

Uploaded by

pillowlily076
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

NIET Python PracticeSet

Uploaded by

pillowlily076
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

National Institute of Engineering and Technology (NIET)

PRACTICE QUESTION SET


Full Marks: 20 | Recommended Time: 1.5 Hours
Syllabus: Units 6–8 (Variables, Data Structures, Control Statements, Strings & Files)

★ PRACTICE SET — For Exam Preparation Only ★


This set reflects the exact pattern, structure, difficulty distribution, and marks breakdown of the upcoming
[Link] it independently under timed conditions for best preparation.

Instructions: Attempt ALL questions. Short answers should be concise. Long answers require
working Python code where asked. Show your reasoning for trace/output questions.

Section A: Short Answer Questions [10 Marks]


Answer ALL six questions. Keep answers brief and precise.

Q1. Write Python statements to:​


(a) Create a tuple of 5 city names.​
(b) Try to change the first element and write what happens. [2 Marks]

Q2. What does the `write()` method do? How is it different from `writelines()`? [1 Mark]

Q3. Predict the output of the following code and explain the result:​

words = ['cat', 'dog', 'bird']​
[Link](1, 'fish')​
[Link]('dog')​
print(words[1])​

[2 Marks]

Q4. What is the output? Explain the role of `else` in a `for` loop in Python — a feature rarely seen in
other languages.​

for n in range(2, 6):​
if n % 4 == 0:​
print('Found:', n)​
break​
else:​
print('Not found') ​

[2 Marks]

Q5. Consider:​

a = {'p': 1, 'q': 2}​
b = [Link]()​
b['p'] = 99​
print(a['p'])​

Now consider:​

a = {'p': [1, 2]}​
b = [Link]()​
b['p'].append(99)​
print(a['p'])​

Both use `.copy()`. Why do they give different results?​

[2 Marks]

Q6. What will be printed? Trace carefully. [1 Mark]​



x = 'abcdef'​
print(x[-2], x[1::2], x[::-2])

Section B: Long Answer Questions [12 Marks]


Attempt ALL three questions. Write complete, working Python code where required. Partial marks awarded.

Q7. Write a Python program that reads a file '[Link]' where each line is in the format:​
RollNo,Name,Marks1,Marks2,Marks3​

Your program must:​
(a) Parse each line and store it as a dictionary in a list.​
(b) Compute each student's total and grade: Total>=80→'A', 60–79→'B', 40–59→'C', below 40→'F'.​
(c) Print a formatted summary to screen (aligned columns).​
(d) Write a new file '[Link]' with columns: RollNo,Name,Total,Grade.​
(e) Handle missing file and invalid (non-numeric) marks gracefully. [4 Marks]

Q8. Study this code carefully and answer all parts:​



fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry']​
result = {}​
for f in fruits:​
key = len(f)​
if key in result:​
result[key].append(f)​
else:​
result[key] = [f]​
print(result)​

(a) Trace the loop and write the exact final output.​
(b) What happens if two fruits have the same length?​
(c) Rewrite the entire loop body as a single dict comprehension (Hint: it isn't straightforward —
explain why a plain comprehension cannot fully replicate this, and show the closest possible
version).​
(d) How would you extract only those keys where more than one fruit exists? [4 Marks]
Q9. Write a Python program for a simple to-do list manager:​
(a) Store tasks in a list of dictionaries, each with keys: 'id', 'task', 'done' (True/False).​
(b) Add at least 5 sample tasks when the program starts.​
(c) Mark a task as done by its id.​
(d) Remove all completed tasks from the list.​
(e) Display remaining tasks sorted alphabetically by task name.​
(f) Save the remaining tasks to a tab-separated file 'todo_remaining.txt'. [4 Marks]

Self-Assessment Checklist
After attempting, use this checklist to review your readiness:
# Skill / Concept Confident?
1 I can predict Python output by tracing code step by step ☐ Yes ☐ No
2 I understand mutable vs immutable types and aliasing side-effects ☐ Yes ☐ No
3 I can read from and write to text and CSV files with error handling ☐ Yes ☐ No
4 I can use lists, tuples, sets, and dictionaries appropriately ☐ Yes ☐ No
5 I understand slicing, negative indexing, and string operations ☐ Yes ☐ No
6 I can write and use for/while loops and if-else conditions correctly ☐ Yes ☐ No
7 I attempted all three long questions and wrote complete code ☐ Yes ☐ No

— End of Practice Set | Best of luck for your examination! —

You might also like