100% found this document useful (1 vote)
270 views

Ch.7 INtroduction to Python Question Answers 2023_24

CBSE CLASS IX - AI BOOK ANS KEY CH.7(GOYAL BROTHERS)

Uploaded by

arshj3859
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
270 views

Ch.7 INtroduction to Python Question Answers 2023_24

CBSE CLASS IX - AI BOOK ANS KEY CH.7(GOYAL BROTHERS)

Uploaded by

arshj3859
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Exercise

Ch. 7 Introduction to Python


A. Multiple choice questions.
1. What is the word (command) used to display numbers and text on the screen?
(a) Print (b) Input
(c) Output (d) Command
Ans: (a) print
2. What is a variable?
(a) A box(memory location) where you store values
(b) a type of graphics
(c) Data type
(d) a type of memory
Ans: (a) A box(memory location) where you store values
3. What symbol is used in python to assign values to a variable?
(a) equals = (b) plus +
(c) forward slash / (d) asterisk *
Ans: (a) equals=
4. What will be the output?
Name='Python'
print (Name)
(a) Python (b) ‘Python’
(c) Name (d) (name)
Ans: (a) Python
5. What would print (10+ 16) produce?
(a) 20 (b) 26
(c) 10+16 (d) (10+16)
Ans: (b) 26
6. What is the name of the environment in Python that write your programs and then
test them out?
(a) Shell (b) Window
(c) IDLE (d) CLI
Ans: (c) IDLE
7. What button do you press to compile (run) your program so that it runs in the shell?
(a) F3 (b) F5
(c) F7 (d) F9
Ans: (b) F5
8. Which is the Python Logo

(a) (b) (c) (d)

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.

C. Answer the following questions.


1. Who developed Python Programming language? Which is the show on which the
language is based?
Ans: Guido Van Rossum developed Python Programming Language. Monty Python’s Flying
Circus is the name of show, on which the language is based.
2. What is the difference between interactive mode and script mode in Python?
Ans: Interactive mode execute one command at a time and then give the output
immediately. It The commands can’t be saved. The script mode allows you to write all
commands in a program and commands are executed sequentially. Commands can be saved
and executed again and again.
3. Which are the applications of Python?
Ans: 1. Amazon uses Python to analyze customer's buying habits and search patterns.
2. Facebook uses Python largely to process images.
3. Google uses Python in its search systems.
4. YouTube uses Python for it's video sharing service.
5. Applications like Instagram, Spotify and Bit Torrent use Python too.
6. NASA uses Python for scientific programming tasks.
7. Python is used in Artificial Intelligence systems.
4. Explain IDLE and its main purpose.
Ans: IDLE is Python's Integrated Development and Learning Environment and is an
alternative to the command line. As the name may imply, IDLE is very useful for developing
new code or learning Python.
The main purpose of IDLE are:

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. What is the role of indentation in Python?


Ans: In Python, indentation is required for indicating what block of code, a statement
belongs to. Indentation is basically used in flow of control statements (like for, if, etc). We
can give any number of spaces for indentation, but all the statements in a block must have
the same indent, that means the same number of spaces.
6. What do you understand by Typecasting in Python with the help of examples?
Ans: In explicit type conversion, users convert the data type of an object to the required
data type.
We use the predefined functions like int(), float(), complex(), bool(), str(), tuple), list(), dict(),
etc. to perform explicit type conversion.
This type conversion is also called typecasting because the user casts (change) the data type
of the objects.
Example:
a = 144
b = 144.0
c = 69
print('Variable a converted into string ', str(a) )
print('Variable a converted into float ', float(a))
print('Variable b converted into integer', int(b))
7. Comments are an easy way to enhance readability and understandability of a program.
Which operator is used to write a comment in Python? Elaborate with examples.
Ans: Comments in Python start with the hash character, #, and extend to the end of the
physical line.
Single-line comments are created simply by beginning a line with the hash (#) character, and
they automatically terminated by the end of line. Example:
#This is a comment
print("Hello, World!")
Comments can be placed at the end of a line, and Python will ignore the rest of the line.
Example:
print("Hello, World!") #This is a comment
Comments that span multiple lines used to explain things in more detail, are created by
adding a character (''' triple quote) on each end of a comment.
Example:
Example: '''This is a multi line comment
Written in
more than just one line '''
8. How will you convert string to an integer in Python?
Ans: >>>y=int(input('Enter your Marks'))
Data entered by the user is converted from string to integer and then assigned to y.
9. Write any four features of Python.
Ans: Features of Python
A. Python language is freely available, which means it doesn't cost anything to use
Python.
B. It is open source, so it can be freely modified and redistributed.
C. Python uses a few keywords and clear, simple English like structure.

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)

E. Practice based questions.


1. Write Python code to calculate and display the selling price of an item by inputting the cost price
and profit.
Program Output:
CP=eval(input("Enter the Cost Price:")) Enter the Cost Price:1000
PP=eval(input("Enter the profit percentage:")) Enter the profit percentage:30
SP=CP+PP/100*CP The selling price of the item is :
print("The selling price of the item is :",SP) 1300.0

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

You might also like