100% found this document useful (1 vote)
2K views

Python L1 Assignments Topgear Hima 284446

This document contains 10 coding questions related to Python programming. For each question, the code and output are blank, indicating the questions are for students to code and test solutions. The questions cover a range of Python topics including functions, strings, files, lists, dictionaries, and XML parsing.

Uploaded by

subhani shaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views

Python L1 Assignments Topgear Hima 284446

This document contains 10 coding questions related to Python programming. For each question, the code and output are blank, indicating the questions are for students to code and test solutions. The questions cover a range of Python topics including functions, strings, files, lists, dictionaries, and XML parsing.

Uploaded by

subhani shaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Python L1 Assignments:

1. What will be the output of 'seclist' in print commands of below code?


mylist = range(4)
seclist = mylist
print seclist
mylist.append(4)
print seclist
seclist = mylist[:]
print seclist
mylist.append(5)
print seclist

Code:

Output:

Sensitivity: Internal & Restricted


2. What is the output of following code:
def f(n):
for x in range(n):
yield x**3

for x in f(6):
print x

Code:

Output:

------------------------------------------------------------------------------------------------------------------------------------------
3. Write a program to receive a string from keyboard and check if the string has two 'e' in the characters.
If yes return True else False.

Code:

Output:

Sensitivity: Internal & Restricted


4. What is the output of following code:
counter = 1
def dolots(count):
global counter
for i in (1, 2, 3):
counter = count + i

print dolots(4)
print counter

Code:

Output:

Sensitivity: Internal & Restricted


5. Write a code to read the data from input file called input.txt and count the number of characters per
line, number of words per line and write these into output file called as output.txt

Input File:

Code:

Output:

Sensitivity: Internal & Restricted


6. Create 3 Lists ( list1,list2,list3) with numbers and perform following operations
a) Create Maxlist by taking 2 maximum elements from each list.
b) Find average value from all the elements of Maxlist.
c) Create a Minlist by taking 2 minimum elements from each list
d) Find the average value from all the elements of Minlist

Code:

Sensitivity: Internal & Restricted


Output:

Sensitivity: Internal & Restricted


7. Write program to convert prefix/net mask to IP
e.g.: input:16 output: 255.255.0.0

Code:

Output:

------------------------------------------------------------------------------------------------------------------------------------------
8. Create a suitable data construct to read the data from an xml document as shown below:
<bookstore shelf="New Arrivals">
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentius</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">

Sensitivity: Internal & Restricted


<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

Code:

Output:

Sensitivity: Internal & Restricted


9. Create a suitable object type and check for file size of 0 bytes of the directory contents as shown
below:

02/15/2016 10:49 PM 962 switchfinal.py


02/15/2016 10:49 PM 943 switchfinal.py.bak
01/27/2016 11:46 AM 15 t.py
03/31/2016 12:39 PM 840 t1.py
01/25/2016 10:34 AM 2,407 tc1.py
02/14/2017 09:13 AM 0 teat.py
03/15/2016 05:52 PM 5 tes.py

Code:

Output:

Sensitivity: Internal & Restricted


10.Create a suitable object type to eliminate the duplicate elements

Code:

Output:

Sensitivity: Internal & Restricted

You might also like