Ch.7 INtroduction to Python Question Answers 2023_24
Ch.7 INtroduction to Python Question Answers 2023_24
1|Page
Ans: (b)
9. What is an input function in Python?
(a) A function that allows us to ask the user to enter some data.
(b) To plug in something.
(c) Data displayed on a screen.
(d) A function
Ans: A function that allows us to ask the user to enter some data.
10. What function is used to output a message in python?
(a) print(") (b) input=name
(c) print (d) name=input
Ans: (c) print
11. How would you print a text string?
(a) output 'Hello!' (b) print ('Hello!')
(c) print (Hellol) (d) output (Hello!)
Ans: (b) print ('Hello!')
12. Which symbol do we use if we want to add a comment to our code?
(a) @ (b) #
(c) * (d) &
Ans: (b) #
13. To create a variable named new_var and assign it a value of 81 divided by 9, which
statement would you use?
(a) new_var = 81 \9 (b) new_var = '81/9'
(c) new_var = '81\9' (d) new_var = 81/9
Ans: (d) new_var = 81/9
14. Choose the statement that assigns 4 to the power of 3 to the variable new_var...
(a) new_var = 4 **3 (b) new_var = 3 ** 4
(c) new var = 3 ** 4 (d) new_var = 4 ^^ 3
Ans: (b) new_var = 3 ** 4
15. Which of the following is a float?
(a) new_var = 1234 (b) new_var = True
(c) new_var = 1.234 (d) new_var = 'True'
Ans: (c) new_var = 1.234
16. How would you output new_var = 123 as a text string?
(a) print(str(new_var)) (b) print new_var.str
(c) print str[new_var] (d) print (new_var).str()
Ans: (a) print(str(new_var))
17. Numbers with a decimal point belong to a type called..
(a) Pointing (b) Integers
(c) decimal (d) float
Ans: (d) float
18. To create a newline at the end of a prompt, you can use which of the following
expressions?
(a) \new (b) \return
(c) break (d) \n
Ans: (d) \n
19. A __________ expression is an expression that is either True or False.
(a) Boolean (b) Truth
2|Page
(c) Variable (d) Conditional
Ans: (a) Boolean
20. Which of these is not a legal numeric type in Python?
(a) Int (b) Float
(c) Decimal (d) Boolean
Ans: (c) Decimal
21. Which one of these is integer division?
(a) / (b)//
(c)% (d) None of the above
Ans: (b)//
22. Is Python case sensitive when dealing with variables?
(a) Yes (b) No
(c) Machine dependent (d) none of the above
Ans: (a) Yes
23. What is the maximum possible length of a variable?
(a) 31 characters (b) 63 characters
(c) 79 characters (d) none of the mentioned
Ans: (c) 79 characters
24. All keywords in Python except True, False and None are in,
(a) lower case (b) UPPER CASE
(c) Capitalized (d) None of the mentioned
Ans: (a) lower case
25. Which is the correct operator for power (Xy)?
(a) X^Y (b) X**Y
(c) X^^y (d) None of the mentioned
Ans: (b) X**Y
26. What is the answer to this expression, 22 % 3 is?
(a) 7 (b) 1
(c) 0 (d) 5
Ans: (b) 1
27. Mathematical operations can be performed on a string.
(a) True (b) False
Ans: (a) True Note: only + and *
28. Operators with the same precedence are evaluated in which manner?
(a) Left to Right (b) Right to Left
(c) Can't say (d) None of the mentioned
Ans: (a) Left to Right
29. What is the output of this expression, 3*1**3?
(a) 27 (b) 9
(c) 3 (d) 1
Ans: (c) 3
30. Which one of the following has the same precedence level?
(a) Addition and Subtraction
(b) Multiplication, Division and Addition
(c) Multiplication, Division, Addition and Subtraction
(d) Addition and Multiplication
Ans: (a) Addition and Subtraction
31. The expression int(x) implies that the variable x is converted to integer.
(a) True (b) False
3|Page
Ans: (a) True
32. Which one of the following has the highest precedence in the expression?
(a) Exponential (b) Addition
(c) Multiplication (d) Parentheses
Ans: (d) Parentheses
33. Select all options that print hello-how-are-you
(a) print('hello, 'how', 'are', you') (b) print("'hello', 'how', 'are', 'you'+' * 4)
(c) print('hello-' + 'how-are-you') (d) print('hello' + ' + 'how' +'-'+ 'are' + 'you')
Ans: (c) print('hello-' + 'how-are-you')
(d) Which of the following symbol is used to indicate the line as a comment?
(a) // (b) “
(c)/*/ (d)#
Ans: (d)#
B. Fill in the blanks.
1. In. script mode of Python, the interpreter is no longer active.
2. .py is the extension of a Python program.
3. IDLE is an acronym for Integrated Development and Learning Environment.
4. Comparison operators are also called relational operators.
5. Relational operators are used for comparison of values.
6. The values the operator uses are called operands.
7. Implicit type conversion automatically converts one data type to another data type.
8. Python supports three different numerical types namely integer, floats and complex
number.
9. Explicit Type Conversion is also called type casting.
10. Comments can be used to make the code more understandable.
4|Page
• Multi-window text editor with syntax highlighting, autocompletion and smart indent.
• Python shell with syntax highlighting and Integrated debugger.
• Automatic indentation (useful for beginners learning about Python's indentation).
5|Page
D. Python can run on a variety of platforms- Windows, Linux, Macintosh, smart phones
(Android, i0S), etc.
E. Python supports procedure oriented as well as object-oriented programming.
F. It supports graphical user interface.
G. It is compatible with C, C+ languages, etc.
H. There are a variety of applications of this language. Python is used in Game
development, database applications, web applications, Artificial Intelligence, etc.
10. What are the two ways to use Python interpreter?
Ans: There are two modes of interacting with Python i.e. Interactive mode and Script mode.
Interactive Mode: Interactive mode of working means you type the command - one
command at a time, and the Python executes the given command there and then and gives
you the output. In this kind of mode, you have to type the command in front of Python
command prompt >>> .
For example, if you type 4+5 in front of Python Prompt, it will give you the result as 9.
Working in Script Mode: The script mode allows you to write all the commands in a
program and execute the program. The commands in the program are executed
sequentially. All the errors of the program are shown together after the e
11. What are the rules for naming a variable?
Ans: Variable naming conventions:
1. Variable names are case sensitive. For e.g. num and NUM are treated as two
different variables.
2. Keywords or words with special meaning, should not be used as the variable names.
3. Variable names should be short and meaningful.
4. All variable names must begin with a letter or an underscore .
5. After the first initial letter, variable names may contain letters and digits (0 to 9) and
an underscore (_) but no spaces or special characters are allowed.
6. Examples of valid variable names: last_name, name, name1, _name
7. Examples of invalid variable names: last-name, 9marks, marks%
12. What are the different arithmetic operators used in Python? Write their precedence
too.
Ans: The different arithmetic operators used in Python are: *,/, +,-, %,**,and //.
Precedence of arithmetic operators in decreasing order
a. () (Parentheses)
b. **(Exponentiation)
c. -(Negation) (Division)
d. // (Integer Division) * (Multiplication) % (Modulus)
e. +(Addition) - (Subtraction)
13. What do you mean by precedence of operators? Give examples.
Ans: Operator precedence determines which operator is performed first in an expression
with more than one operator with different precedence.
Precedence of operators:
a. () (Parentheses)
b. **(Exponentiation)
c. -(Negation) (Division)
d. /(Division),* (Multiplication), % (Modulus), // (Integer Division)
e. +(Addition) - (Subtraction)
f. <,>, <=, >= Comparison operators
g. == , !=
h. Logical NOT
6|Page
i. Logical AND
j. Logical OR
D. Predict the output of the following code.
1.
a=1 Answer: 2 2
a,b= a+1,a+1
print(a,b)
2.
x.y=7, 2 Note: correction: print(x,y)
x,y,x=x+1,y+3,x+10 Answer: 17 5
print(x,y)
3.
P=10 Answer: 60 480
Q=20
P*=Q//3 Note: correction P*Q//3
Q+=P+Q**2
print(P, Q)
4.
A=5 Answer: 20 300
B=10
A+=A+B
B*=A+B
print(A,B)
5.
x,y=2,6 Answer: 6 4
x,y=y,x+2
print(x, y)
2. Write Python code to accept the side of a square and print its area.
Program Output:
side=eval(input("Enter the side of the square:")) Enter the side of the square:6
area=side*side The area of the square is: 36.0 Unit
print("Area of the square :", area, "Square unit") Square
3. Write Python code to input the temperature in Celsius and convert it into Fahrenheit using the
formula (F=C*9/5+322)
Program Output:
T=eval(input("Enter the temp. in Degree C:")) Enter the temp. in Degree C:36
F=T*9/5+32 The temp. in F: 96.8
print("The temp. in F:",F)
4. Write Python code that accepts marks in 5 subjects and outputs average marks.
Program Output:
M1,M2,M3,M4,M5=eval(input("Enter the marks in 5 Enter the marks in 5 Subjects:
Subjects:")) 67,78,89,67,78
Total=M1+M2+M3+M4+M5 The average marks: 75.8
7|Page
Avg=Total/5
print("The average marks:", Avg)
5. Write Python code to input a number and print its square and cube.
Program Output:
N=eval(input("Enter the Number: ")) Enter the Number: 5
Sqr=N**2 The square of : 5 is= 25
Cube=N**3 The cube of : 5 is= 125
print("The square of:",N, "is=",Sqr)
print("The cube of:",N, "is=",Cube)
6. Write Python code that takes amount in dollars and the conversion rate of dollars to rupees
price, it then returns the amount converted to rupees.
Program Output:
Dollars=eval(input("Enter the Dollars:")) Enter the Dollars:56
CR=eval((input("Enter the Conversion rate:")) Enter the Conversion rate:73
Amt=Dollars*CR The amount in Rupees is : 4088.0
print("The amount in Rupees is :", Amt)
8|Page