0% found this document useful (0 votes)
37 views4 pages

22ise251-Qb-Module 2 Updated 1

Uploaded by

dreamsmystic05
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)
37 views4 pages

22ise251-Qb-Module 2 Updated 1

Uploaded by

dreamsmystic05
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/ 4

GLOBAL ACADEMY OF TECHNOLOGY

An Autonomous Institute, Affiliated to VTU Belagavi


Approved by AICTE, Accredited by NAAC ’A’Grade
Ideal Homes Township, Rajarajeshwari Nagar, Bengaluru–560098

Department of Information Science and engineering


(Accredited by NBA 2022-2025)

Question Bank

Semester: II Course Name: Python Programming (Integrated)


Course Code: 22ISE251 Academic Year: 2022-2023 ( Even Semester)

Module 2
Functions

1. Define Function. Explain the function declaration in python with an example.


2. Explain parameters and arguments in a function with suitable example.
3. Describe return values and return statement used in functions with an example.
4. Explain Local variable and Local scope in the functions with an example.
5. Explain Global variable and Global scope in the functions with an example.
6. Demonstrate the need of Global keyword in the functions.
7. Demonstrate with example how Local Variables cannot be used in the Global scope.
8. Demonstrate with example how Global Variables can be read from a Local scope.
9. Explain with suitable example local and global variables with the same name.
10. Define Exception Handling. Write a Python program with exception handling code to solve divide-
by-zero error situation.
11. Define a Python function with suitable parameters to generate prime numbers between two integer
values. Write a Python program which accepts two integer values m and n.
(note: m>0, n>0 and m < n) as inputs and pass these values to the function. Suitable error messages
should be displayed if the conditions for input values are not followed.

12. Write a function named collatz() that has one parameter named number.
 If number is even, thencollatz() should print number // 2 and return this value.
 If number is odd, then collatz() should print and return 3 * number + 1.
 Then write a program that lets the user type in an integer and that keeps calling
collatz() on thatnumber until the function returns the value 1.

Prepared by Faculty, Python Programming, GAT Page | 1


13. Define a Python function with suitable parameters to generate first N Fibonacci numbers. The first
two Fibonacci numbers are 0 and 1 and the Fibonacci sequence is defined as a function F as
Fn = Fn-1 + Fn-2. Write a Python program which accepts a value for N (where N >0) as input and pass
this value to the function. Display suitable error message if the condition for input value is not
followed.

14. Write a Python function to take an integer as an argument and return the day of the week using elif
statement.

15. Write a Python function to return the smallest of two numbers.


16. Write a Python function to return sum of first N natural numbers.
17. Write a Python function to find factorial of a number.
18. Write a Python program to print the absolute value using function.
19. Write a function called check-season, it takes a month parameter and returns the season: Autumn,
Winter, Spring or Summer.
20. Write a python program to GuessTheNumber random number generated between 1 to 20 using function.

Prepared by Faculty, Python Programming, GAT Page | 2


Question Bank

Semester: II Course Name: Python Programming (Integrated)


Course Code: 22ISE251 Academic Year: 2022-2023 ( Even Semester)

Module 2
Lists
1. Define List in Python. Explain how lists are created and accessed with suitable example.
2. Explain the working of following List Methods in Python with suitable examples.
 index() method
 insert() method
 remove() method
 sort() method
 append() method

3. Explain the working of in and not in Operators in List with suitable examples.
4. Demonstrate the following in Python
 Getting a List’s Length with len() function
 Changing Values in a List with Indexes
 Getting sub-lists with Slices
 List Concatenation and List Replication
 Removing Values from Lists with del Statements

5. Given the following List in Python


spam= [2, 4, 6, 8, 10]
What do following statements evaluate to?
 spam[int('2')*2]
 spam[-1]
 spam[:2]
 spam[int('3' * 2) / 11]
 spam[12/4]
6. Given the following List in Python
val = ['cat', 'bat', 'rat', 'elephant’]
What do following statements evaluate to?
 val[1:3]
 val[0:-1]
 val[:2]
 val[1:]
 val[:]

Prepared by Faculty, Python Programming, GAT Page | 3


7. Given the following List in Python
bacon=[3.14, 'cat', 11, 'cat', True]
What do following statements evaluate to?
 bacon. index('cat')
 bacon. append (99)
 bacon. remove('cat')
 bacon. insert (2,12)

8. Given the following List in Python


val=[12, 78, 'Hello', True, 78]
Evaluate the following statements.
 print(val.index(666))
 val.insert(12,’GM’)
 val.remove(78)
 val.remove(555)

9. Write a Python program to initialize with values in a list, input two positions a and b, swap
elements in the positions a and b, print the modified list.
10. Write a Python program to
 Declare the empty list by the name sample
 Update the list value to 1, 2, 3, 4, 5 in sequence
 Insert value 10 at position 3 and print list
 Swap first element with last element
 Print the list after each operation

11. Write a Python program to initialize a list with 10 integers, sort them in descending order and print
the modified list.
12. Given the following List.
spam = ['apples', 'bananas', 'tofu', 'cats']
Write a function in Python that takes a list value as an argument and returns a string with all the
items separated by a comma and a space, with and inserted before the last item. For example, passing
the previous spam list to the function would return 'apples, bananas, tofu, and cats'. But your function
should be able to work with any list value passed to it.
13. Write a Python program to find sum of all the items in a list using function.
14. Write a Python program to count positive and negative numbers in a List.
15. Write a Python program to count Even and Odd numbers in a List.
16. Write a Python program to find product of all the items in a list using function.

Prepared by Faculty, Python Programming, GAT Page | 4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy