0% found this document useful (0 votes)
8 views4 pages

IX Ch-2 Introduction To Python (Python Manual)

Uploaded by

aaravkr302010
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
8 views4 pages

IX Ch-2 Introduction To Python (Python Manual)

Uploaded by

aaravkr302010
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

Q/A cum topic-wise notes

Topic: Introduction to Python (Python Content Manual)

Q1) What is a programming language? (page 21)


• A programming language is a formal language that specifies a set of instructions that can be used to
produce various kinds of output.
• In simple Words, a programming language is a vocabulary and set of grammatical rules for instructing a
computer to perform specific tasks.
• Though there are many different programming languages such as BASIC, Pascal, C, C++, Java, Haskell,
Ruby, Python, etc.

Q2) What is a program? (page 21)


A computer program is a collection of instructions that perform a specific task when executed by a computer.
It is usually written by a computer programmer in a programming language.

Q3) What is Python? (page 21)


• Python is a programming language. It is a cross-platform programming language, meaning, it runs on
multiple platforms like Windows, MacOS and Linux.
• Python was created by Guido Van Rossum and released in 1991.
• It follows both procedural and object-oriented programming approach.
• To write and run Python program, we need to have Python interpreter installed in our computer.

Q4) What are the key features of python? (page 22)


1. Python is easy to learn, read and maintain because it has few keywords, simple structure and easy
syntax rules.
2. Python has a broad Standard library with plenty of built in functions to solve variety of problems.
3. Python supports an Interactive mode which allows interactive testing and debugging of code.
4. Python supports portability and compatibility as it can run on a wide variety of operating systems and
hardware platforms.
5. Python interpreter can be extended by adding low-level modules to make the programmers work
efficiently.
6. Python provides interfaces to all major open source and commercial databases.

Q5) Mention various applications of python. (page 23)


• Python can be used to develop the following:
• Web and internet applications
• Business applications
• Games and 3D graphics
• Database Access
• Software
• Desktop GUI applications

Q6) What are the different modes for coding in python? (page 29, 30)
Python shell can be used in two ways, interactive mode and script mode.
1. Interactive Mode, as the name suggests, allows us to interact with OS. Working in interactive mode is
convenient for beginners and for testing small pieces of code, as we can test them immediately.
2. Script mode lets us create and edit Python source files. For coding more than few lines, we should
always save our code so that we may modify and reuse the code.
Note: Result produced by Interpreter in both the modes, viz., Interactive and script mode is exactly the same.
Q7) What are comments in python? List down the various types of comments. (32, 33)
A comment is text that doesn't affect the output of a code, and ignored by the python interpreter.
It is just a piece of text to let someone know what you have done in a program or what is being done in a
block of code.
It is basically the internal documentation of the source code.
We can write comments in two ways:
1. Single Line comments, we use the hash (#) symbol to start writing a comment.
2. Multi-line comments, we start and end the multiline comments with triple (“““) quotes.

Q8) What is an identifier? What are the different properties of an identifier? (page 35)
An identifier is a name given to entities like class, functions, variables, etc. It helps to differentiate one entity
from another.
Properties or naming rules of an identifier:

Q9) What is a variable? Give example. (page 35, 36)


A variable is a named location used to store data in the memory. It is helpful to think of variables as a
container that holds data which can be changed later throughout programming.
For example,
Assigning a value to a variable
Website = "xyz.com" # first assignment is the initial value of the variable
Changing value of a variable
Website = "xyz.com"
Website = "abc.com" # latest value of variable Website will be printed as “abc.com”
Assigning different values to different variables
a, b, c=5, 3.2, "Hello" # this statement will result into a=5, b=3.2 and c=”Hello”
Assigning same value to different variables
x=y=z= "Python" # this statement will result into x=”Python”, b=”Python” and c=”Python”

Q10) Write short note on, Keywords and Statements with example of each. (page 32, 33)
Statements are the instructions written in the source code for execution. There are different types of
statements in the Python programming language like Assignment statement, Conditional statement, Looping
statements etc. These help the user to get the required output. For example, n = 50 is an assignment
statement.

Keywords are the reserved words in Python used by Python interpreter to recognize the structure of the
program. For example, if, elif and else are the keywords to implement the conditional structure in a program.
Q11) What is a constant? Give example. (page 37)
A constant is a type of variable whose value cannot be changed. It is helpful to think of constants as containers
that hold information which cannot be changed.
It is achieved by creating a module with constants and later the module can be imported in other programs.
Constants are written in all capital letters and underscores separating the words.

Example to Assign value to a constant in Python


• Create a info.py
NAME = "Ajay" # initializing the constant variables NAME and AGE
AGE = 24

• Create a main.py
import info
print(info.NAME) # accessing the constant variable defined in info.py
print(info.AGE) # value of nfo.NAME and info.AGE cannot be changed

Q12) What are the rules and conventions for naming of variables. (page 38)
Rules for naming variables and constants are same as identifier naming rules given in answer 8.
Conventions are the guidelines for good programming:

Q13) Explain python output function with the help of an example. (page 41)
We use the print() function to output data to the standard output device (screen).
An example is given below.
a = "Hello World!"
print(a)
OUTPUT:
Hello World!

a = "tarun"
print("My name is :",a)
OUTPUT:
My name is : tarun

x = 1.3
print("x = \n", x) # \n is to add a new line
OUTPUT:
x=
1.3

m = 6
print(" I have %d apples", m) #%d is the format specifier for integer variables
OUTPUT:
I have 6 apples
Q14) What are Python operators? Explain the Arithmetic operators. (page 41)
Operators are special symbols which represent computation. They are applied on operand(s), which can be
values or variables. Same operators can behave differently on different data types. Operators when applied on
operands form an expression. Operators are categorized as Arithmetic, Relational, Logical and Assignment.
Value and variables when used with operator are known as operands.
Different Arithmetic operators and the operation they perform:
Operator Meaning Example Working Output
+ Addition 20+10 Sum of 20 and 10 30
- Subtraction 20-10 10 is subtracted from 20 10
* Multiplication 20*10 20 is multiplied by 10 200
/ Division 33/10 Returns quotient (fractional) 4.3
// Integer Division 43/10 Returns quotient (integer) 4
% Modulus 43/10 Returns the remainder after division 3
** Exponent 3**3 Returns 3X3X3 27

Arithmetic Operators precedence: From highest to lowest precedence,


** (exponential) - highest
* (multiplication), / (division)
+ (addition), - (subtraction) - lowest
Note: Expression inside the parentheses () is evaluated first

Python statement:
print( 12 + 5 * (8 – 2) / 10)
Expression: 12 + 5 * 8 – 2 / 10
Operators: +, *, -, /
Operands: 12, 5, 8, 2, 10

Q15) Write a program to calculate the simple interest with output.


PROGRAM CODE:
p_amt, time, rate=100000, 2, 2.5.
print('The principal amount is', p_amt)
print('The time period is', time)
print('The rate of interest is',rate)
si = (p_amt * time * rate)/100
print('The Simple Interest is', si)

OUTPUT:
The principal amount is 100000
The time period is 2
The rate of interest is 2.5
The Simple Interest is 5000.0

Q16) Write a program to convert the Celsius temperature into Fahrenheit.


PROGRAM CODE:
celsius = 99 # Initialize the Celsius temperature
fahrenheit = (celsius * 9/5) + 32 # Convert Celsius to Fahrenheit
print("Temperature in Fahrenheit:", fahrenheit) # Display the result

OUTPUT:
Temperature in Celsius: 99
Temperature in Fahrenheit: 210.2

You might also like