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

Python 6-Week Assignment Guide

Uploaded by

ss7944844
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)
6 views3 pages

Python 6-Week Assignment Guide

Uploaded by

ss7944844
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

■ Python 6-Week Assignment Pack (CSE 20 + CSE

30)
■ Week 1 — Python Basics & Data Types
Topics: Variables, expressions, statements, basic I/O, data types

MCQs:
1. What will type(3.0) return?
a) int b) float c) double d) str
2. print("5" * 3) → ?
a) 15 b) 555 c) error d) None
3. Invalid variable name?
a) _count b) count1 c) 1count d) count_

Debugging:
num = input("Enter number: ")
square = num * num
print("Square is: " + square)

Practice:
1. Area of circle
2. Celsius to Fahrenheit
3. Print name and age

■ Week 2 — Control Structures


Topics: if-elif-else, while, for

MCQs:
1. Output of if/elif chain example?
a) A b) B c) A then B d) C
2. Loop for unknown iterations?
a) for b) while c) do-while d) None

Debugging:
count = 5
while count > 0:
print(count)
count -= 1

Practice:
1. FizzBuzz
2. Guessing game

■ Week 3 — Functions, Strings, Data Structures


MCQs:
1. Correct function definition?
a) def myfunc {} b) function myfunc(): c) def myfunc(): d) myfunc def():
2. s[::-1] for "hello"?
a) hello b) olleh c) error d) h

Debugging:
def add(a, b):
return a + b
print(add(2))
Practice:
1. Count vowels
2. Student topper dictionary
3. Remove duplicates

■ Week 4 — File I/O, Error Handling, Intro to OOP


MCQs:
1. Mode to overwrite file?
a) r b) w c) a d) rw
2. Purpose of __init__?
a) destroy b) init attrs c) copy obj d) none

Debugging:
file = open("[Link]", "r")
data = [Link]()
print(data)
[Link]

Practice:
1. BankAccount class
2. Division by zero handling
3. Count words in file

■ Week 5 — Advanced Python: OOP, Iterators, Generators, Recursion


MCQs:
1. Generator yield example output?
a) 1 2 b) 2 1 c) error d) None
2. Recursion truth?
a) call twice b) base case c) faster than loops d) no args

Debugging:
class Animal: ... class Dog(Animal): def speak(): ...

Practice:
1. Even number generator
2. Factorial recursion
3. Employee with private attrs

■ Week 6 — Algorithms, Functional Programming, Mini-Projects


MCQs:
1. Graph shortest path module?
a) graph b) networkx c) math d) numpy
2. reduce(lambda x,y: x+y, [1,2,3])?
a) 6 b) [6] c) (6,) d) error

Debugging:
from functools import map
nums = [1,2,3] squares = map(lambda x: x*x nums)

Practice:
1. BFS
2. Coin change DP
3. To-Do CLI app
■ Additional DSA Practice Questions
Strings:
Reverse string, palindrome check, char freq, longest non-repeat substring, anagram check
Arrays/Lists:
Max/min without built-in, rotate list, second largest, remove value, sum pairs
Bit Manipulation:
Count set bits, power of 2 check, swap without var, unique number, reverse bits
Sets:
Manual union/intersection, find duplicates, disjoint check, diff, symmetric diff
Dictionaries:
Word freq, invert dict, merge sum values, max value key, group by first letter
Tuples:
Sort by second elem, unpack, most common, tuple->dict, merge tuples
Recursion:
Factorial, Fibonacci, Tower of Hanoi, reverse string, prime check
Matrix:
Spiral print, transpose, multiply, sum, search in sorted matrix
Functions:
Varargs sum, Armstrong, min & max, flatten list, memoization
OOP:
Student class, multiple inheritance, + overload, instance counter, abstract Shape class

Common questions

Powered by AI

The '__init__' method initializes an object's attributes at creation, ensuring that an object starts with a consistent state .

Memoization improves efficiency by storing previously computed results of recursive calls, thus avoiding redundant calculations and reducing time complexity in cases like Fibonacci numbers .

Using 'w' mode overwrites the file, which is advantageous when the existing data is irrelevant or obsolete. In contrast, 'a' mode appends data, useful for maintaining previous entries .

The result would be 6. The reduce function applies the lambda function cumulatively to the elements of the list, starting with the first two elements: (1 + 2) gives 3, then (3 + 3) results in 6 .

Without a base case, the recursive function would continue calling itself indefinitely, leading to a stack overflow error as the recursion depth exceeds system limits .

Not handling division by zero can result in runtime errors that crash the program, disrupting user experience and potentially leading to data loss or corruption .

A 'while' loop is preferred when the number of iterations is not known beforehand and depends on a condition evaluated at runtime, such as waiting for user input or a random event .

Generators evaluate elements lazily, producing them on-the-fly, which saves memory by not storing the entire dataset in memory at once, unlike lists that hold all their elements .

Variable names in Python must begin with a letter (a-z, A-Z) or an underscore (_). '1count' starts with a numeral, which makes it invalid .

Encapsulation restricts access to certain object components, leading to code modularity by allowing internal changes without affecting other code parts. It enhances security by protecting object integrity .

You might also like