0% found this document useful (0 votes)
3 views6 pages

Ques&Ans Notes For Python Chapter

The document provides an introduction to Python, covering basic concepts such as the Python prompt, print function, variable assignment, and modes of operation. It includes fill-in-the-blank exercises, true or false questions, and explanations of Python's features like data types, input/output functions, and variable naming rules. Additionally, it presents sample Python programs demonstrating simple tasks like printing messages and performing arithmetic operations.

Uploaded by

wethelynns
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)
3 views6 pages

Ques&Ans Notes For Python Chapter

The document provides an introduction to Python, covering basic concepts such as the Python prompt, print function, variable assignment, and modes of operation. It includes fill-in-the-blank exercises, true or false questions, and explanations of Python's features like data types, input/output functions, and variable naming rules. Additionally, it presents sample Python programs demonstrating simple tasks like printing messages and performing arithmetic operations.

Uploaded by

wethelynns
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/ 6

Introduction to Python

A. Fill in the blanks:


1. >>> is the Python prompt.
2. The arguments in a print () function are separated by commas.
3. There are two modes in Python.
4. The three separators used with print () function are ‘,’, ‘\t’ and ‘\n’.
5. The int() function is used to convert the entered data into an integer.
6. “.py” is the extension for Python files.
7. Key combination to save the file is Ctrl + S.
8. Values are assigned to variables using the assignment operator (=).

B. True or False:
1. You can save the file in Interactive mode. False (We can save the file only in
Script mode.)
2. Float () function is used to convert the entered data into a float or decimal
number. True
3. “input” is a key word in Python. True
4. In Python, a string can be entered either in single or double quotes. True
5. Character data type is available in Python. False (Not available only string is
available)
6. To run a Python module, press the F6 key. False (Press F5)
7. A variable has a fixed value. False (not fixed. It can be changed)
C. Write whether the following variable names are valid or invalid. If it is invalid,
write the reason for it:
1. Employee_Code - Valid
2. Employee Code - Invalid since space is not allowed.
3. 9Star - Invalid since it can not start with a numeric value.
4. print - Invalid since print is a keyword in Python.
5. Class8.A - Invalid since special characters are not allowed.
6. ABC@Ltd -Invalid since special characters are not allowed.

C. Answer the following questions:


1. What is Python?
Ans: Python is an interpreted, Object-oriented, high-level programming
language.

2. What is the use of Python?


Ans: Python is used for building apps, developing web sites, performing data
analysis, statistical analysis and building machine learning models.
3. What are the two modes in Python?
Ans: The two modes in Python are Interactive mode and Script mode.

4. Explain the Interactive mode.


Ans: In Interactive mode, we could type the commands next to Python prompt
one-by-one. Then if we press ‘Enter’ key, Python will immediately give the
output for each of them.

5. What is the use of Script mode?


Ans: The Script mode is used to create and edit lengthy Python programs. The
complete script is written in an editor. Here, we can also save the file for future
use.

6. What are variables?


Named storage locations in the computer memory, which are used to store data
temporarily are called Variables.

7. Explain the rules to write a variable name.


Ans: Rules to write a variable name are:
(i) A variable name must start with an alphabet (capital or small) or underscore (
_)
(ii) It can consist of letters, digits and underscore. No other character is allowed.
(iii) A keyword cannot be used as a variable name.
(iv) A variable name can be of any length.
(v) Variable names are case sensitive. (eg: Age and age are different variable
names).

8. How can you assign a value to a variable? Explain with examples.


Ans:
Values are assigned to variables using the assignment operator (=).
Eg:
1. a=10, Here the value 10 is assigned to the variable ‘a’.
2. b=20+30, Here the value 50 is assigned to the variable ‘b’.
3. c=a+b, here the sum of values of a and b is assigned to the variable “c”(i.e 60
is assigned)
9. What is a data type? Explain the different datatypes in Python.
Ans: A data type represents the type of data stored in a variable.
Python has the following data types:
(i) Integer(int): It contains positive or negative whole numbers. Eg: 67, -98
(ii) Float: It is a real number with floating point representation. It is specified by
a decimal point. Eg: 3.14, -6.7
(iii) String: It is a collection of one or more characters put in a single quote,
double-quote or triple quote. In Python there is no character data type. Eg:
‘Hello’, “India”

10. What is the use of input( ) function?


Ans: It is used to accept the value for a variable from the user. To input integer
and float values, you can use int( ) or float( ) along with the input( ) function.

11. What is the use of print( ) function? Explain the three separators used with
the print( ) function.
Ans: Print( ) function is used to print a message or value.
The three separators used are:
(i) Using (,) operator: when (,) separator is used, the values are displayed with a
space between them.
(ii) Using tab space(‘\t’): When (‘\t’) separator is used, the values are displayed
with a tab space between them.
(iii) Using newline character (‘\n’): A newline character in Python is used to end
a line and start a new line. This can be used with both input( ) and print( )
functions.
C. Write Python programs for the following:
1. To print “Hello World”.
Ans:
print(“Hello World”)
2. To initialise a variable ‘b’ with the value of 50 and print it:
Ans:
b = 50
print(“The value of b is:”,b)

3. To add two numbers 250 and 300 by assigning the values to the variables..
Ans:
a=250
b=300
Print(“The sum of two numbers is:”, a+b)

4. Write a program to get the values of three numbers during the run time and
display its sum value.
a=int(input(“Enter the First number:”))
b=int(input(“Enter the Second number.”))
c=int(input(“Enter the Third number:”))
print(“The sum of the values is:”, a+b+c)
5. Print the three values a=10, b=56 and c=87,using the three separators-‘,’ ,’\t’
and ‘\n’:
Ans:
a=10
b=56
c=87
print(a,b,c)
print(‘\n’)
print(a, ‘\t’, b, ‘\t’, c)
print(‘\n’,a, ‘\n’, b, ‘\n’, c)

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