Docsity

CS101 INTRODUCTION TO PYTHON PROGRAMMING.pdf, Exams of Nursing

Toggle sidebar
bg1
CS101 INTRODUCTION TO PYTHON
PROGRAMMING — BS 1ST
SEMESTER COMPLETE SOLVED
ASSIGNMENT 2026
---
## TABLE OF CONTENTS
1. Section A: Multiple Choice Questions … 1–30
2. Section B: Short Questions … 31–50
3. Section C: Predict the Output … 51–65
4. Section D: Debugging Exercises … 66–75
5. Section E: Coding Problems … 76–100
---
## SECTION A: MULTIPLE CHOICE QUESTIONS (1–30)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39

Partial preview of the text

Download CS101 INTRODUCTION TO PYTHON PROGRAMMING.pdf and more Exams Nursing in PDF only on Docsity!

CS101 INTRODUCTION TO PYTHON

PROGRAMMING — BS 1ST

SEMESTER COMPLETE SOLVED

ASSIGNMENT 2026

## TABLE OF CONTENTS

  1. Section A: Multiple Choice Questions … 1– 30
  2. Section B: Short Questions … 31– 50
  3. Section C: Predict the Output … 51– 65
  4. Section D: Debugging Exercises … 66– 75
  5. Section E: Coding Problems … 76– 100

SECTION A: MULTIPLE CHOICE QUESTIONS (1–30)

  1. Which of the following is a valid Python variable name? A) 2nd_value B) total_marks C) class D) my-var Answer: B Explanation: Variable names cannot start with a digit, cannot be a keyword (class), and cannot contain hyphens. total_marks is valid.
  1. What is the output of print(type(10))? A) B) C) ``
  1. What is the output of print(10 // 3)? A) 3. B) 3 C) 4 D) 1 Answer: B Explanation: // is floor division. 10 // 3 gives 3.
  1. Which data type is immutable? A) List B) Dictionary C) Set D) Tuple

Answer: D Explanation: Tuples are immutable; lists, dictionaries, and sets are mutable.

  1. What is the correct way to create a list in Python? A) my_list = (1, 2, 3) B) my_list = [1, 2, 3] C) my_list = {1, 2, 3} D) my_list = <1, 2, 3> Answer: B Explanation: Lists are created with square brackets [].

Answer: A Explanation: input() reads a string from the user.

  1. What is the output of print(bool(0))? A) True B) False C) 0 D) Error Answer: B Explanation: 0 is falsy, so bool(0) returns False.
  1. Which statement is used to exit a loop prematurely? A) continue B) pass C) break D) return Answer: C Explanation: break exits the loop immediately.
  1. What is the output of print(2 3 2)? A) 64 B) 512 C) 256 D) 128
  1. What is the output of print("Hello" + " " + "World")? A) HelloWorld B) Hello World C) Hello+World D) Error Answer: B Explanation: String concatenation joins strings: "Hello World".
  1. Which method is used to add an item to the end of a list? A) append() B) insert() C) add() D) push()

Answer: A Explanation: append() adds an item to the end of a list.

  1. What is the output of print(3 "abc")? A) abcabcabc B) abc C) Error D) 3abc Answer: A Explanation: String repetition: "abc" repeated 3 times.
  1. Which of the following is NOT a valid Python data type?

Answer: B Explanation: Modulus returns the remainder: 10 % 3 = 1.

  1. Which keyword is used to handle exceptions? A) try B) catch C) except D) Both A and C Answer: D Explanation: Python uses try and except for exception handling.
  1. What is the output of print(list(range(3)))?

A) [1, 2, 3]

B) [0, 1, 2]

C) [0, 1, 2, 3]

D) [3]

Answer: B Explanation: range(3) produces 0, 1, 2.

  1. Which of the following is used to open a file in Python? A) open() B) file() C) fopen() D) read() Answer: A

A) Tuple B) String C) List D) Integer Answer: C Explanation: Lists are mutable; tuples, strings, and integers are immutable.

  1. What is the output of print("Python"[0])? A) P B) y C) n D) Error Answer: A

Explanation: Indexing starts at 0, so "Python"[0] is 'P'.

  1. Which statement is used to skip the current iteration of a loop? A) break B) continue C) pass D) return Answer: B Explanation: continue skips the rest of the current iteration and moves to the next.
  1. What is the output of print(1, 2, 3, sep="-")?

Explanation: Dictionaries use key-value pairs in curly braces.

  1. What is the output of print(2 + 3 4)? A) 20 B) 14 C) 24 D) 11 Answer: B Explanation: Multiplication has higher precedence: 2 + (3 4) = 14.
  1. Which of the following is used to define a class in Python?

A) class MyClass: B) def MyClass: C) struct MyClass: D) object MyClass: Answer: A Explanation: Classes are defined with the class keyword.

  1. What is the output of print("abc" 0)? A) abc B) 0 C) Empty string D) Error Answer: C