0% found this document useful (0 votes)
5 views8 pages

Programming With Python 3528

This document is a question paper for a programming course focused on Python, containing various questions and tasks related to Python programming concepts. It includes sections on data structures, flowcharts, error handling, and file operations, along with specific coding tasks and theoretical questions. Candidates are instructed to follow specific guidelines while attempting the questions, with a total of 16 questions to choose from.

Uploaded by

mail2prachi.637
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)
5 views8 pages

Programming With Python 3528

This document is a question paper for a programming course focused on Python, containing various questions and tasks related to Python programming concepts. It includes sections on data structures, flowcharts, error handling, and file operations, along with specific coding tasks and theoretical questions. Candidates are instructed to follow specific guidelines while attempting the questions, with a total of 16 questions to choose from.

Uploaded by

mail2prachi.637
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/ 8

3528 16 [This question paper contains 16 pti:org~.2..

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

(v) Write Python statement to print alternate I


Semester
values from my _tuple.
Duration : 3 Hours Maximum Marks : 90

Instructions for Candidates

1. Write your Roll No. on the top immediately on receipt


of this question paper.

2. Question 1 in Section A is compulsory.

3. Attempt any 4 questions from Section B.

Section A

1. (a) Draw a flowchart for a Python program that takes


an integer input, checks if it is even or odd, and
prints the result accordingly. (3)

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

(v) Display the list in the reverse order.


(vi) forEach

(c) Consider the following python code: ( c) Consider the following Python code : (5)
(3)

employees-= my_tuple = (10, 20, 30, 40, 50)


'ElOl': 'John',
'El02': 'Emma',
'E103': 'Sophia' Answer the following questions based on the code
above:
print(employees[E104])
employees.update(E105, 'Michael')
print(employees.get('E106', 'Employee not found')) (i) What is the type of my_tuple? How can
del employees('E102')
you confirm that it is a tuple?

(i) Identify all errors in the code.


(ii) Write a Python statement to access the
(ii) Explain why each error occurs. third element of the tuple my_tuple and
print it.

P.T.O.
3528 14 3528 3

Perform the following tasks : (d) Consider the following dictionary : (3)

1\

(i) Print all the keys in the dictionary.


grades = {'Alice': 85, 'Bob': 90, 'Charlie': 78)

Write a Python program to :


(ii) Remove the product "Mouse" from the

dictionary. (i) Add a new entry for "David" with a grade


of 92.
(iii) Print the keys beginning with the character

'M'. (ii) Update the grade for "Alice" to 88.

(iv) Check if the product "Keyboard" exists in (iii) Print the contents of updated dictionary.

the dictionary. If it does, print its quantity.


( e) Write Python statements to perform the following
(v) Print all the values that are less than operations on the string message = "hello world,

10. welcome to Python programming" (3)

(i) Find the frequency of the character 'o' in


(b) Write a Python program to perform the following
the string.
operations on a list of integers entered by the
(5) (ii) Replace all occurrences of the character
user:
T with the character 'z'.
(i) Accept a list of integers from the user
(iii) Remove the first occurrence of the
(input as a single line of space separated
character 'e' from the string.
numbers).

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

X += 5 that may occur while reading the updated


y *= 2 content of the file. If an error occurs, print
z -= 3 "An error occurred while reading the file".

(h) Write Python statements for the following


operations : (3) 7. (a) Create a Python dictionary named inventory that
stores five product names as keys and their
(i) Concatenate two strings: "Hello" and
"World" with a space in between and quantities as values. (5)
assign to variable named my_string.

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).

(i) Describe the behavior of the for loop when the


(b) Write a while loop in python that performs the
step value in range(start, stop, step) is : (3)
following tasks : (4)
(i) Positive
(i) Prompt the user to input numbers.
(ii) Negative
(ii) Keep a running total of the numbers
(iii) Zero (Discuss why using zero as a step
entered. value results in an error)

(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)

valid numbers entered. (i) my_tuple = (10, 20, 30)

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)

5. (a) Write a Python program that uses an if-elif-else


Section B statement to determine both the maximum and
minimum values among three given numbers.
2. (a) Write a function to print the following pattern: (4)
(5)
A (b) Differentiate between the given operators.
BB Illustrate with examples. (6)
CCC
(i) or and and
DDDD
EEEEE
(ii) = and ==

(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 :

(10, 'Python', 3.14, True). (i) print( calculate(70))

(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'))

(b) Write a Python function called count_vowels that


( c) Consider the Python code snippet below : (5)
accepts a string as an argument and returns the
count of vowels (a, e, i, o, u) in the string. T.he try:
num = int(input("Enter a number: "))
program should prompt the user to enter a string, result= 100 / num
print("Result:", result)
pass it to the function, and display the count of
except ValueError:
vowels. (5) print("Invalid input! Please enter an integer.")
except ZeroDivisionError:
print("Division by zero is not allowed.")
( c) Write the output of the following Python codes :
(4) What will be the output if the user enters the
(i) for i in range(l, 6): following inputs :

(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)?

(iii) What is the output of print(contains

(b) Write Python Program that performs the following journey)?

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

Use exception handling to catch text?

FileNotFoundError and print "File does not


(v) What 1s the output of print(sub_text) if
exist."
sub_text=text[0 :8]?
(ii) Display the contents of the file.

4. (a) Write a Python program that performs the


following task : (6)

P.T.O.

You might also like