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

Assignment 1 - Basics of Python

The document outlines 13 questions providing examples of basic Python programming tasks. The questions cover: manipulating lists, dictionaries and sets through various operations; generating random values and strings; finding common/unique values between lists; writing data to files in specific formats; calculating time for operations; and analyzing student mark data. The goal is to write Python code to complete the tasks and gain experience with Python basics.

Uploaded by

hhhhhhh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
156 views

Assignment 1 - Basics of Python

The document outlines 13 questions providing examples of basic Python programming tasks. The questions cover: manipulating lists, dictionaries and sets through various operations; generating random values and strings; finding common/unique values between lists; writing data to files in specific formats; calculating time for operations; and analyzing student mark data. The goal is to write Python code to complete the tasks and gain experience with Python basics.

Uploaded by

hhhhhhh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

------------------------------------------------------------------------

Assignment No. 1 (Python Basics)


------------------------------------------------------------------------

Q1. L is a list defined as L= [11, 12, 13, 14].


(i) WAP to add 50 and 60 to L.
(ii) WAP to remove 11 and 13from L.
(iii) WAP to sort L in ascending order.
(iv) WAP to sort L in descending order.
(v) WAP to search for 13 in L.
(vi) WAP to count the number of elements present in L.
(vii) WAP to sum all the elements in L.
(viii) WAP to sum all ODD numbers in L.
(ix) WAP to sum all EVEN numbers in L.
(x) WAP to sum all PRIME numbers in L.
(xi) WAP to clear all the elements in L.
(xii) WAP to delete L.

Q2. D is a dictionary defined as D= {1:5.6, 2:7.8, 3:6.6, 4:8.7, 5:7.7}.


(i) WAP to add new entry in D; key=8 and value is 8.8
(ii) WAP to remove key=2.
(iii) WAP to check weather 6 key is present in D.
(iv) WAP to count the number of elements present in D.
(v) WAP to add all the values present D.
(vi) WAP to update the value of 3 to 7.1.
(vii) WAP to clear the dictionary.

Q3. S1 is a set defined as S1= [10, 20, 30, 40, 50, 60].
S2 is a set defined as S2= [40, 50, 60, 70, 80, 90].
(i) WAP to add 55 and 66 in Set S1.
(ii) WAP to remove 10 and 30 from Set S1.
(iii) WAP to check whether 40 is present in S1.
(iv) WAP to find the union between S1 and S2.
(v) WAP to find the intersection between S1 and S2.
(vi) WAP to find the S1 - S2.

Q4. Write the following program.


(i) WAP to print 100 random strings whose length between 6 and 8.
(ii) WAP to print all prime numbers between 600 and 800.
(iii) WAP to print all numbers between 100 and 1000 that are divisible by 7 and 9.

Q5. WAP to create two lists of 10 random numbers between 10 and 30; Find
(i) Common numbers in the two lists
(ii) Unique numbers in both the list
(iii) Minimum in both the list
(iv) Maximum in both the list
(v) Sum of both the lists

Q6. WAP to create a list of 100 random numbers between 100 and 900. Count and print the:
(i) All odd numbers
(ii) All even numbers
(iii) All prime numbers

Q7. D is a dictionary defined as D={1:"One",2:"Two",3:"Three",4:"Four", 5:"Five"}.


WAP to read all the keys and values from dictionary and write to the file in the given below format.
Key1, Value1
Key2, Value2
Key3, Value3

Q8. L is a list defined as L={"One","Two","Three","Four","Five"}.


WAP to count the length of reach element from a list and write to the file in the given below format:
One, 3
Two, 3
Four, 4

Q9. Write to the file 100 random strings whose length between 10 and 15.

Q10. Write to the file all prime numbers between 600 and 800.

Q11. WAP to calculate the time taken by a program.

Q12. WAP to sort following number of elements in a list, calculate time taken and plot the graph.
Number of elements in list Time Taken
50k T1
100k T2
150k T3
200k T4
250k T5

Q13. WAP to create a dictionary of student marks in five subjects and you have to find the student
having maximum and minimum average marks.

You might also like