Programming With Python 3528
Programming With Python 3528
s:- ( E)
Your Roll . ~~l-'.!f;i<l'....
(iii) Can you modify the value of the second
element in the tuple my_tuple? Justify vour
answer.
Sr. ·No. of Question Paper: 3528 f~
A'
...
<J: \;
#'t
'-~
( xi-- :<;'
~:i,
Unique Paper Code 2344001102 o)""k ,,::':'
(iv) Write Python code to check if the number •Yapuri.~''
40 exists in my_tuple and print "Found" if Name of the Paper Programming with Python
it exists, otherwise print "Not Found".
Name of the Course GE Computer Science
Section A
P.T.O.
(1000}
3528 2 3528 15
(b) Identify valid/invalid identifiers from the following : (ii) Find and print the largest and smallest
• (3)
numbers in the list.
(i) FirstName
(ii) Total@Amount (iii) Remove any duplicate values from the list
and print the updated list in sorted order.
(iii) $Balance_ Sheet
(iv) class (iv) Calculate and print the sum of all even
numbers in the list.
(v) _temp Value
(c) Consider the following python code: ( c) Consider the following Python code : (5)
(3)
P.T.O.
3528 14 3528 3
Perform the following tasks : (d) Consider the following dictionary : (3)
1\
(iv) Check if the product "Keyboard" exists in (iii) Print the contents of updated dictionary.
P.T.O.
3528 4 3528 13
(f) What is the output of the following code? (3) (i) Create a text file named "students.txt" and
write the names of 5 students into the file,
y = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
result= 0 each on a new line.
for i in y:
if i % 2 == 0: (ii) Use exception handling to open the file in
result+= i
print (result) read mode and display the contents on the
screen. If the file is not found, print "File
(g) What will be the final value of x, y and z when not found".
the python code, as shown below, is executed?
(3) (iii) Append the name "John Doe" to the file
X = 12
without deleting the existing content.
y = 5
z = 7
(iv) Use a try-except block to handle any errors
P.T.O.
3528 12 3528 5
6. (a) Write a function that accepts two positive (ii) Slice my_string to extract only the first 5
characters and assign to variable named
integers, a and b and returns a list of all the even '
sliced_string.
numbers between a and b (including a and not
(3) (iii) Split my_string into a list of words.
including b).
(iii) End the input process when the user types G) Examine the Python code snippets below, identify
"stop". any errors, and provide an explanation for why
these errors occur, if applicable, for each part.
(iv) Display the total sum and the count of all (3)
my_tuple[l] = 40
(c) Write a Python program that performs the print(my_tuple)
following tasks using file handling and exception
(8) (ii) my_set = {1, 2, [3, 4]}
handling:
print(my _set)
P.T.O.
3528 6 3528 11
(iii) my_tuple = ("Ram", "Mohan", "Raj") (ii) for i in range(}, 6):
my_set = set(my_tuple) if i == 3:
continue
my_set.add("Rahul ")
print(i)
print(my_set)
(b) Consider the following python code (5) (iii) is and is not
score = 80
( c) Write a Python program to calculate the factorial
def calculate (score, bonus = 10) of a given positive integer entered by the user,
score= score+ bonus ensuring that the input is valid and displaying an
error message for invalid input. (5)
return score
P.T.O.
3528 10 3528 7
(i) Create a tuple with mixed data types: What will be the output of following :
(ii) Access and print the second and last (ii) print(calculate(60, 15))
elements of the tuple.
(iii) print( calculate(bonus=20))
(iii) Modify a tuple element and catch the
(iv) print(calculate(90, 5, 10))
exception raised.
(v) print(calculate(score='Hello', bonus=' World'))
(i) "abc"
if i == 3:
(ii) 0
break
(iii) 5
print(i)
Explain why these exceptions occur.
P.T.O.
3528 8 3528 9
3. (a) Write a Program to Prompt for a Score between ( c) Consider the following Python code : (5)
0.0 and 1.0. If the Score is out 6 of range, print ,,
an error. If the score is between 0.0 and 1.0, text= "Learning is a continuous journey"
print a grade using the following table (6) sub_text = text[9:18]
uppercase_text = text.upper()
contains_journey = "journey" in text
Score Grade
>=0.9 A Answer the following questions :
>=0.8 B
>=0.7 C (i) What is the output of print(sub_text)?
>=0.6 D
<0.6 F (ii) What is the output of print(uppercase_text)?
tasks: (4)
(iv) Write python code to check if the word
(i) Open a file named data.csv in read mode. "learning" (case-insensitive) is present in
P.T.O.