0% found this document useful (0 votes)
9 views3 pages

Python Programming (11 AI)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Python Programming (11 AI)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 3

NOTES ON

PART A: Employability skills


Unit 3: Python Programming

Python Editors :There are various editors and Integrated Development Environments (IDEs) that
you can use to work with Python. Some popular options are PyCharm, Spyder, Jupyter Notebook,
IDLE, Google Colab etc. Let us look at how we can work with Jupyter Notebook. Jupyter Notebook
is an open-source web application that allows you to create and share documents containing live
code, equations, visualizations, and narrative text.
Jupiter Notebook: To install Jupiter Notebook pip library is used.
ex. pip install notebook
Tokens:
Python program consists of Tokens. It is the smallest unit of a program that the interpreter or
compiler recognizes. Tokens consist of keywords, identifiers, literals, operators, and punctuators.

Keywords Reserved words are used for special purposes. List of keywords are given below.
If , for while, print, input..........

Identifier An identifier is a name used to identify a variable, function, class, module or other
object. Generally, keywords (list given above) are not used as variables. Identifiers cannot start with
digit and it can’t contain any special characters except underscore.

Literals: Literals are the raw data values that are explicitly specified in a program. Different types
of Literals in Python are String Literal, Numeric Literal (Numbers), Boolean Literal (True & False),
Special Literal (None) and Literal Collections.
Operators: Operators are symbols or keywords that perform operations on operands to produce a
result.
Punctuators: Common punctuators in Python include : ( ) [ ] { } , ; . ` ' ' " " / \ & @ ! ? | ~ etc.
Control flow statements in Python

Selection
Statement
The if/
if..else statement evaluates test expression and the statements written below will execute if the
condition is true otherwise the statements below else will get executed. Indentation is used to
separate the blocks. Syntax:

Looping Statements Looping statements in programming languages allow you to execute a block
of code repeatedly.

For loop For loop iterates through a portion of a program based on a sequence, which is an ordered
collection of items. The “for” keyword is used to start the loop. The loop variable takes on each
value in the specified sequence (e.g., list, string, range). The colon (:) at the end of the for statement
indicates the start of the loop body. The statements within the loop body are executed for each
iteration.
Answer the following questions
1) Who Develop python?
Python is a general-purpose, high level programming language. It was created by Guido van
Rossum, and released in 1991.

2) input() function accepts the value as string only. How can you convert string to int?
Using int( ) function together with input( ), we can convert string to int.

3) What are variables? What are the rules of declaring variables in Python?
Named labels whose value can be used and processed during program run. Generally, keywords (list
given above) are not used as variables. Variable names cannot start with digit and also it can’t
contain any special characters except underscore.
4) What is data type?
Data types are the classification or categorization of data items. It represents the kind of value that
tells what operations can be performed on a particular data.
5) What do you mean by type casting?
A variable of particular datatype can be converted into another datatype using some functions. The
explicit conversion of an operand to a specific type is called type casting.
6) “Python supports dynamic typing”, True or False. Justify your answer.
True. . Python automatically determines the variable's data type based on its value. It infers the data
type from the value, and this is why Python is often called a "dynamicallytyped" language.
7) Name any four features of python language.
❖ High Level language
❖ Interpreted Language
❖ Free and Open Source
❖ Platform Independent (Cross-Platform)
8) Give examples for keywords.
and, as, continue, if, not try, del, pass
9) Define an operator and provide examples of different operators along with their functions.
Operators are symbols or keywords that perform operations on operands to produce a result.
Python supports a wide range of operators:
• Arithmetic operators (+, -, *, /, %)
• Relational operators (==, !=, <, >, <=, >=)
• Assignment operators (=, +=, -=)
• Logical operators (and, or, not)
• Bitwise operators (&, |, ^, <<, >>)
• Identity operators ( is, is not)
• Membership operators (in, not in)

10. Multiple choice questions


1. Identify the datatype
L = “45” a. String b. int c. float d. tuple
2. Which of the following function converts a string to an integer in python?
a. int(x) b. long(x) c. float(x) d.str(x)
3. Which special symbol is used to add comments in python?
a. $ b.// c. /*.... */ d.#
4. Which of the following variable is valid?
a. Str name b.1str c._str d.#Str
5. Elements in the list are enclosed in _____ brackets
a. ( ) b. { } c. [ ] d. /* */
6. Index value of last element in list is ____________________
a. 0 b.-10 c. -1 d.10
7. What will be the output of the following code?
a = [10,20,30,40,50]
print(a[0])
a.20 b.50 c. 10 d.40
8. Name the function that displays the data type of the variable.
a. data( ) b. type( ) c. datatype( ) d. int( )

ANSWERS
1. a. String
2. a. int(x)
3. d. #
4. c. _str
5. c. [ ]
6. c. -1
7. c. 10
8. b. Type( )
11) Practice Programs
1. Write a Tipper program where the user inputs the total restaurant bill. The program
should then display two amounts: 15 percent tip and 20 percent tip.
2. Write a program to check whether the user is eligible for driving license or not
3. Your father always gives his car for service after 15000 km. Check whether his car needs
service or not. Read the kilometer reading from the user and give the output.
4. Write a program to display the first ten even natural numbers (use for loop).
5. Write a program to accept the Basic salary from the user and calculate the Net Salary. Net
Salary= Basic Salary + HRA + DA -PF HRA=30% of Basic DA=20% of Basic PF=12% of
Basic

You might also like