0% found this document useful (0 votes)
7 views

python

Uploaded by

arnabbag484
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)
7 views

python

Uploaded by

arnabbag484
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
You are on page 1/ 2

INDEX

Sl no. Assignment name Page no. sSignature


1 The Interpreter as a calculator. Basic arithmetic operations. Introduction 1-3
to the simple numeric data types – integers, floating point numbers,
Boolean, complex numbers. Inter conversion of data types.
a. Use the Python prompt as a basic calculator. Explore the order of
operations using parentheses.
b. Explore the various functions in the math module. Eg: find GCD of two
numbers, area and perimeter of circle using math.pi, etc.
c. Exploring the complex data type and their operations, eg: finding the
modulus and phase angle of a complex number.
d. The print function – Printing value. Repeat the previous experiments
now using the print function solve using python.

2 Basic user interactions using the print() and input() functions. 4-5
a. Write a simple python script using the print function in a text editor,
save it with the extension “.py”. Run it in the terminal / command
prompt.
b. Take input two strings from the user, and print the first one twice, and
the other one thrice.
c. Ask the user to enter two numbers, and output the sum, product,
difference, and the GCD.
d. More programs that test concepts learned in week 1 which involves
the usage of the print and input functions.

3 Strings, List, Tuples, the re (regular expression) module 6-7


a. Ask the user for two strings, print a new string where the first string is
reversed, and the second string is converted to upper case. Sample
strings: “Pets“, “party”, output: “steP PARTY”. Only use string slicing and
+ operators.
b. From a list of words, join all the words in the odd and even indices to
form two strings. Use list slicing and join methods.
c. Simulate a stack and a queue using lists. Note that the queue deletion
operation won’t run in O(1) time.
d. Explore the ‘re’ module, especially re.split, re.join, re.search and
re.match methods.
4 Conditionals, looping constructs, and generators 8-10
a. Use list comprehension to find all the odd numbers and numbers
divisible by 3 from a list of numbers.
b. Using while loops to do Gaussian addition on a list having an even
number of numbers. Print each partial sum. Eg: if the list is [1, 2, 3, 4, 5,
6], the program should output “1 + 6”, “2 + 5”, and “3+4” in separate
lines, and the result of the addition “21”. Extend it to handle lists of odd
length.
c. Primarily testing using for and while loops.
d. Use (c) to generate a list of primes within a user-given range.
e. Explore the ‘key’ function of sum( ), min( ), max( ), and sort( ) functions
using lambdas.
5 User defined functions 11-13
a. Implement popular sorting algorithms like quick sort and merge sort to
sort lists of numbers.
b. Implement the Pascal’s triangle.
c. Three positive integers a, b, and c are Pythagorean triples if a2 + b2 =c 2
. Write a function to generate all Pythagorean triples in a certain range.
d. Write two functions that simulate the toss of a fair coin, and the roll of
an unbiased ‘n’ sided die using the random module.
e. Like (d), but now the coin and the die are not fair, with each outcome
having a given probability.
6 File handling, sys, pickle and csv modules 14-16
a. Basic file operations. Explore the different file modes.
b. Emulate the unix ‘cp’, ‘grep’, ‘cat’ programs in Python. In each case,
the user should pass the arguments to the program as command line
arguments.
c. Use pickle for persistent storage of variables.
7 Sets and dictionaries 17-19
a. Use sets to de-duplicate a list of numbers, and a string such that they
contain only the unique elements
b. Use the set union and intersection operations to implement the
Jaccard and Cosine similarity of two sets.
c. Use dictionaries to count the word and letter occurrences in a long
string of text.
d. Invert a dictionary such the previous keys become values and values
keys. Eg: if the initial and inverted dictionaries are d1 and d2, where d1 =
{1: ‘a’, 2: ‘b’, 3: 120}, then d2 = {‘a’: 1, 2: ‘b’, 120: 3}.
e. What if the values in (d) are not immutable? Use frozensets. For
repeated values, use lists. Eg: if d1 = {1: ‘a’, 2: ‘a’, 4: [1, 2]}, then d2 = {‘a’:
[1, 2], frozenset([1, 2]): 4}.
f. Write a function to generate the Fibonacci numbers in (a) exponential
time using the naïve algorithm, and (b) in linear time using dynamic
programming (memorization) with a dictionary.

You might also like