Professional Documents
Culture Documents
i Pu Cs Chapter 5 Q&A-1
i Pu Cs Chapter 5 Q&A-1
VSA SA LA E TOTAL
1 FIB (1 HOT)
MCQ
- d) A high-level language
- a) Python
- b) C++
- c) Assembly
- d) 0s and 1s
- Answer: d) 0s and 1s
- d) Hardware description
- a) C++
- b) Assembly
- c) Python
- d) Machine language
- Answer: c) Python
2
5. Which quote is attributed to Donald Knuth in the textbook?
- a) "Programming is fun."
- b) Case-sensitive
- c) Platform-dependent
- Answer: c) Platform-dependent
- a) $
- b) %
- c) &
- d) >>>
- Answer: d) >>>
3
8. What is the extension of Python source code files?
- a) .java
- b) .py
- c) .exe
- d) .txt
- Answer: b) .py
PRIMUS PU COLLEGE, BANGALORE
- a) Script mode
- b) Interactive mode
- c) Batch mode
- d) Compiled mode
- a) print
- b) import
- c) function
4
- d) main
- Answer: b) import
- a) 123abc
- b) abc123
- c) a!bc
- d) None of these
- a) A reserved word
- b) A function
- d) A type of operator
- a) //
- b) #
5
- c) @
- d) &
- Answer: b) #
- a) Variable
- b) Function
- c) Object
PRIMUS PU COLLEGE, BANGALORE
- d) Keyword
- Answer: c) Object
- a) id()
- b) identity()
- c) object_id()
- d) get_id()
- Answer: a) id()
- b) Case-sensitive
- d) Requires a compiler
- a) while
- b) assert
- c) print
- d) pass
- Answer: c) print
19. What is the output of the following Python code: `print("Hello, World!")`?
7
- a) Hello, World!
- b) "Hello, World!"
- c) print("Hello, World!")
- d) Syntax Error
- b) Python is case-sensitive.
- a) // This is a comment
- b) /* This is a comment */
- c) # This is a comment
8
22. Which of the following is NOT a Python data type?
- a) Integer
- b) String
- c) Boolean
- d) Character
- Answer: d) Character
- d) By declaring it first
- a) Curly braces
- b) Parentheses
- c) Tabs or spaces
- d) Semicolons
- a) 20
- b) 14
- c) 24
- d) 12
- Answer: b) 14
PRIMUS PU COLLEGE, BANGALORE
26. Which Python function is used to get input from the user?
- a) input()
- b) read()
- c) scanf()
- d) get_input()
- Answer: a) input()
27. What does the following Python code do: `name = input("Enter your name:
")`?
- b) Assigns the string "Enter your name: " to the variable name
- c) Prompts the user to enter their name and stores it in the variable name
10
- d) Generates a syntax error
- Answer: c) Prompts the user to enter their name and stores it in the variable
name
- a) var1
- b) _var
- c) 1var
- Answer: c) 1var
- a) 3.3333333333333335
- b) 3
- c) 3.0
- d) 10
- Answer: a) 3.3333333333333335
- a) +
11
- b) -
- c) *
- d) &&
- Answer: d) &&
- a) `string s = "Hello"`
- b) `s = 'Hello'`
PRIMUS PU COLLEGE, BANGALORE
- c) `s = Hello`
- d) `string s = 'Hello'`
- Answer: b) `s = 'Hello'`
32. Which of the following methods can be used to convert a string to a list in
Python?
- a) list()
- b) split()
- c) convert()
- d) str()
- Answer: b) split()
12
33. Which of the following is NOT a valid Python data type?
- a) List
- b) Tuple
- c) Dictionary
- d) Array
- Answer: d) Array
34. What is the output of the following code: `print("Hello" + " " + "World")`?
- a) Hello World
- c) "Hello World"
- d) Hello + World
- a) ^
- b) **
- c) exp()
- d) pow()
- Answer: b)
13
36. Which of the following is a mutable data type in Python?
- a) String
- b) Tuple
- c) List
- d) Integer
- Answer: c) List
PRIMUS PU COLLEGE, BANGALORE
- a) 5
- b) 6
- c) 8
- d) 9
- Answer: c) 8
38. Which function is used to read input from the user in Python 3.x?
- a) input()
- b) raw_input()
- c) scan()
- d) read()
14
- Answer: a) input()
39. Which of the following statements will create a tuple in Python?
- a) t = [1, 2, 3]
- b) t = {1, 2, 3}
- c) t = (1, 2, 3)
- d) t = 1, 2, 3
- Answer: c) t = (1, 2, 3)
- a) <class 'tuple'>
- b) <class 'list'>
- c) <class 'set'>
- d) <class 'dict'>
41. Which of the following operators is used for string concatenation in Python?
- a) +
- b) &
- c) .
- d) concat()
15
- Answer: a) +
42. What is the correct way to declare a variable in Python?
- a) var x = 5
- b) x := 5
- c) int x = 5
- d) x = 5
PRIMUS PU COLLEGE, BANGALORE
- Answer: d) x = 5
43. What will be the output of the following code: `print(10 % 3)`?
- a) 1
- b) 3
- c) 10
- d) 0.3
- Answer: a) 1
44. Which method is used to remove an item from a list in Python by its value?
- a) remove()
- b) pop()
16
- c) delete()
- d) discard()
- Answer: a) remove()
- a) True
- b) False
- d) 5
- Answer: a) True
46. Which method can be used to convert a list into a tuple in Python?
- a) tuple()
- b) list_to_tuple()
- c) to_tuple()
- d) convert()
- Answer: a) tuple()
- c) Parentheses
- d) Square brackets
- Answer: a) Indentation
- a) type()
PRIMUS PU COLLEGE, BANGALORE
- b) isinstance()
- c) id()
- d) obj_type()
- Answer: a) type()
15. What is script mode in Python? In script mode, a Python program is written
in a file, saved, and then executed as a whole.
16. What are Python keywords? Python keywords are reserved words that have
specific meanings to the interpreter and cannot be used as identifiers.
17. Define identifiers in Python. Identifiers are names used to identify variables,
functions, or other entities in a program.
18. What are variables in Python? Variables in Python are names that refer to
objects stored in memory.
19. How are comments added in Python? Comments in Python are added using
the # symbol; everything following the # till the end of the line is treated as a
comment.
20. What is an object in Python? An object in Python is an instance of a data type
that has a unique identity, attributes, and behavior.
21. What is implicit conversion? Implicit conversion is the automatic conversion
of one data type to another by the interpreter.
22. What is explicit conversion? Explicit conversion is the manual conversion of
20 one data type to another using functions like int(), float(), str(), etc.
3-Mark Questions
1. Explain the process of program execution in Python using an interpreter.
o Python uses an interpreter to execute programs. The interpreter
processes the program statements one by one, translating and executing
each statement sequentially until an error is encountered or the entire
program is executed. If an error occurs, execution stops. This contrasts
with a compiler, which translates the entire source code into object code
before execution .
2. What is the significance of the Python prompt >>>?
o The >>> prompt in Python indicates that the interpreter is ready to accept
x = 10
name = "Alice"
they save developers time and effort by offering reusable code for
various functionalities, such as data manipulation, web development,
machine learning, and more. Popular Python libraries include NumPy,
Pandas, Matplotlib, and TensorFlow .
15. Describe how to download and install Python.
o To download and install Python:
1. Visit the official Python website (https://www.python.org/).
2. Download the installer for your operating system.
3. Run the installer and follow the on-screen instructions.
4. Ensure that the option to add Python to the system PATH is
selected.
5. Verify the installation by opening a command prompt or
terminal and typing python --version .
16. What is meant by 'Python is free and open source'?
o Python being 'free and open source' means that it is freely available for
anyone to use, modify, and distribute. The source code of Python is
x = 10 + 5 # 15
y = 10 - 5 # 5
a = 5
b = 10
result = (a == b) # False
x = True
y = False
result = x and y # False
a = 5
a += 3 # 8
a = 10 # 1010 in binary
b = 4 # 0100 in binary
result = a & b # 0000 (0 in decimal)
11. Discuss the role of Python in education and why it is a good choice for
30 learning programming.
o Ease of Learning: Python's simple and readable syntax makes it an
excellent choice for beginners.
o Versatility: Python can be used for various applications, from web
development to data science, providing a broad learning experience.
o Active Community: Python's large and active community offers
extensive resources, tutorials, and support for learners.
o Immediate Feedback: Python's interactive mode allows learners to test
code snippets and receive immediate feedback, facilitating learning.
o Real-world Applications: Learning Python provides practical skills
that are in high demand in the job market, enhancing career prospects.
12. Explain various types of Errors.
Question 1
1. Serial_no.
2. 1st_Room
3. Hundred$
4. total-Marks 31
5. True
Answer:
Question 2
PRIMUS PU COLLEGE, BANGALORE
Answer:
1. length = 10
breadth = 20
2. sum = (length + breadth) / 2
32
3. stationery = ['Paper', 'Gel Pen', 'Eraser']
4. first = 'Mohandas'
middle = 'Karamchand'
last = 'Gandhi'
5. fullname = first + ' ' + middle + ' ' + last
Question 3
Answer:
Question 4
1. 0 == 1 == 2 33
2. 2 + 3 == 4 + 5 == 7
3. 1 < -1 == 3 > 4
Answer:
Question 5
1.
num1 = 4
num2 = num1 + 1
num1 = 2
print(num1, num2)
2.
num1, num2 = 2, 6
num1, num2 = num2, num1 + 2
print(num1, num2)
3.
num1, num2 = 2, 3
num3, num2 = num1, num3 + 1
print(num1, num2, num3)
Answer:
1. 2 5
2. 6 4
3. This code will result in an error because num3 is not defined.
34
Question 6
Which data type will be used to represent the following data values and why?
Answer:
Question 7
1. += num2 + num3 35
print(num1)
2. num1 = num1 ** (num2 + num3)
print(num1)
3. num1 **= num2 + num3
4. num1 = '5' + '5'
print(num1)
5. print(4.00 / (2.0 + 2.0))
6. num1 = 2 + 9 * ((3 * 12) - 8) / 10
print(num1)
7.
num1 = 24 // 4 // 2
print(num1)
8. num1 = float(10)
PRIMUS PU COLLEGE, BANGALORE
print(num1)
9. num1 = int('3.14')
print(num1)
10. print('Bye' == 'BYE')
11. print(10 != 9 and 20 >= 20)
12. print(10 + 6 * 2 ** 2 != 9 // 4 - 3 and 29 >= 29 / 9)
13. print(5 % 10 + 10 < 50 and 29 <= 29)
14. print((0 < 6) or (not(10 == 6) and (10 < 0)))
Answer:
1. 9
2. 4096
3. 4096
4. 55
5. 1.0
6. 25.4
7. 3
8. 10.0
36
9. Error (cannot convert '3.14' to an integer)
10. False
11. True
12. True
13. True
14. True
Question 8
1. 25 / 0
Answer:
Question 9
A dartboard of radius 10 units and the wall it is hanging on are represented using
a two-dimensional coordinate system, with the board’s center at coordinate (0,0).
Variables x and y store the x-coordinate and the y-coordinate of a dart that hits
the dartboard. Write a Python expression using variables x and y that evaluates
to True if the dart hits (is within) the dartboard, and then evaluate the expression
for these dart coordinates:
1. (0,0)
2. (10,10)
3. (6, 6) 37
4. (7,8)
Answer:
Question 10
PRIMUS PU COLLEGE, BANGALORE
Answer:
boiling_point_C = 100
freezing_point_C = 0
38
print(f"Boiling point of water: {boiling_point_F}°F")
print(f"Freezing point of water: {freezing_point_F}°F")Output:
Question 11
Write a Python program to calculate the amount payable if money has been lent
on simple interest. Principal or money lent = P, Rate of interest = R% per annum
and Time = T years. Then Simple Interest (SI) = (P x R x T)/ 100. Amount payable
Answer:
SI = (P * R * T) / 100
amount_payable = P + SI
Question 12
Write a program to calculate in how many days a work will be completed by three
persons A, B and C together. A, B, C take x days, y days and z days respectively
to do the job alone. The formula to calculate the number of days if they work
together is xyz/(xy + yz + xz) days where x, y, and z are given as input to the 39
program.
Answer:
total_days = (x * y * z) / (x * y + y * z + x * z)
print(f"The work will be completed in {total_days} days if A, B, and
PRIMUS PU COLLEGE, BANGALORE
C work together.")
Question 13
Write a program to enter two integers and perform all arithmetic operations on
them.
Answer:
print(f"Addition: {a + b}")
print(f"Subtraction: {a - b}")
print(f"Multiplication: {a * b}")
print(f"Division: {a / b}")
print(f"Modulus: {a % b}")
print(f"Exponentiation: {a ** b}")
print(f"Floor Division: {a // b}")
40
Question 14
Write a program to swap two numbers using a third variable.
Answer:
temp = a
a = b
b = temp
Question 15
Answer:
a, b = b, a
Question 16
Write a program to repeat the string "GOOD MORNING" n times. Here ‘n’ is
an integer entered by the user.
41
Answer:
n = int(input("Enter the number of times to repeat the string: "))
result = "GOOD MORNING " * n
print(result)
Question 17
Answer:
Question 18
Write a Python program to find the volume of spheres with radius 7cm, 12cm,
16cm, respectively.
Answer:
import math
# Input from the user for three spheres (assuming fixed number)
Question 19
Write a program that asks the user to enter their name and age. Print a message
addressed to the user that tells the user the year in which they will turn 100 years
old.
Answer:
43
import datetime
name = input("Enter your name: ")
age = int(input("Enter your age: "))
current_year = datetime.datetime.now().year
year_turning_100 = current_year + (100 - age)
print(f"Hello, {name}! You will turn 100 years old in the year
{year_turning_100}.")
Question 20
PRIMUS PU COLLEGE, BANGALORE
The formula E=mc2 states that the equivalent energy (E) can be calculated as the
mass (m) multiplied by the speed of light (c = about 3×1083 \times 10^83×108 m/s)
squared. Write a program that accepts the mass of an object and determines its
energy.
Answer:
Question 21
Presume that a ladder is put upright against a wall. Let variables length and angle
store the length of the ladder and the angle that it forms with the ground as it
leans against the wall. Write a Python program to compute the height reached by
44
the ladder on the wall for the following values of length and angle:
1. 16 feet and 75 degrees
2. 20 feet and 0 degrees
3. 24 feet and 45 degrees
4. 24 feet and 80 degrees
Answer:
**************
45