0% found this document useful (0 votes)
2 views14 pages

Introduction to python

This document provides an introduction to Python programming, covering its features, data types, operators, and basic programming concepts such as variables, expressions, and control flow. It includes a series of questions and answers to test knowledge on Python syntax and functionality. The document also outlines tasks and programming exercises to reinforce learning.

Uploaded by

advaitkvs4a
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)
2 views14 pages

Introduction to python

This document provides an introduction to Python programming, covering its features, data types, operators, and basic programming concepts such as variables, expressions, and control flow. It includes a series of questions and answers to test knowledge on Python syntax and functionality. The document also outlines tasks and programming exercises to reinforce learning.

Uploaded by

advaitkvs4a
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/ 14

UNIT-5: INTRODUCTION TO PYTHON

• Python is an open-source, high level, interpreter-based language that can be


used for a multitude of scientific and non-scientific computing purposes.
• Comments are non-executable statements in a program.
• An identifier is a user defined name given to a variable or a constant in a
program.
• Process of identifying and removing errors from a computer program is called
debugging.
• Trying to use a variable that has not been assigned a value gives an error.
• There are several data types in Python — integer, Boolean, float, complex,
string, list, tuple, sets, None and dictionary.
• Operators are constructs that manipulate the value of operands. Operators
may be unary or binary.
• An expression is a combination of values, variables, and operators.
• Python has input () function for taking user input.
• Python has print () function to output data to a standard output device.
• The if statement is used for decision making.
• Looping allows sections of code to be executed repeatedly under some
condition.
• for statement can be used to iterate over a range of values or a sequence.
• The statements within the body of for loop are executed till the range of values
is exhausted.
• List is a mutable datatype in python. Elements are stored in a list using square
brackets [ ] . Elements of a list are accessed using its index.

KVS ZIET MYSORE 134


1 mark Questions
1 Who developed Python Programming Language?
a) Wick Van Rossum
b) Rasmus Lerdorf
c) Guido Van Rossum
d) Niene Stom
2 In Python, which of the following characters is used to create single line
comment
a) //
b) #
c) !
d) /*
3 An identifier cannot start with a ________
a) Number
b) Character
c) Underscore
d) None of the above
4 ______________ has a specific meaning in python program
a) Constant
b) Variable
c) Keyword
d) Identifier
5 Write the output of the following python statement
print(10//3)
a) 3
b) 3.33
c) 1
d) 0
6 Which of the following is the valid Python file extension?
a) . python
b) . pl
c) . py
d) . p
7 Numbers with fractions or decimal points are called ________ datatype.

KVS ZIET MYSORE 135


a) Integer
b) String
c) Float
d) None of the above
8 _______is an ordered sequence of letters/characters. They are enclosed in
single quotes (‘ ’ ) or double (“ ”).
a) String
b) Integer
c) Float
d) None of the above
9 ___________ are a sequence of values of any type, and are indexed by integers.
They are immutable and enclosed in ().
a) String
b) Lists
c) Tuples
d) All of the above
10 _________ function is used to display given output in python.
a) printf()
b) print()
c) scan()
d) None of the above
11 _________ function is used to take input from the user in python.
a) input()
b) insert()
c) store()
d) None of the above
12 The data type of 14.5 is __________
a) int
b) float
c) string
d) list
13 ___________ operator gives the remainder in Python.
a) %
b) /
c) //
d) *

KVS ZIET MYSORE 136


14 __________ operator is used to find the square of a number
a) ^
b) *
c) **
d) //
15 What does the following code print?
if 4 + 5 == 10:
print("TRUE")
else:
print("FALSE")
a) TRUE
b) FALSE
c) None of them
d) TRUE FALSE
16 What will be the datatype of following variable?
A= “100”
a) int
b) float
c) string
d) list
17 Smallest element of python coding is called ______
a) Identifiers
b) Tokens
c) Keywords
d) Delimeters
18 Find the invalid variable among the following:
a) 1st_place
b) my_place
c) _first
d) Fun
19 T=[10,20,30,40] is a type of which datatype in python
a) int
b) string
c) list
d) tuple
20 The _________ mode of python gives instant result of typed statement

KVS ZIET MYSORE 137


a) Interactive mode
b) Script mode
c) Combination of interactive and script mode
d) All of these
2 mark Questions
1 What is the Difference between Interactive mode and script mode?
2 What are the basic datatypes in Python?
3 What is a variable?
4 What are the arithmetic operators in Python?
5 What are lists in python?
6 What will be out of the following?
for I in range(1,10,2):
print(I)
7 What does the following code print?
if 4 + 5 == 10:
print("TRUE")
else:
print("FALSE")
8 L=[10, “New”, 34.5,30,40]
print( L[1])
L[2]=50
print(L)
9 What will be the output of the following
print (“hello \n” )
print(“Class 9\n Artificial Intelligence”)
10 State True or False
a) Python is case sensitive programming language
b) A variable’s value once assigned cannot be changed
11 Identify the datatype in the following
a) 15.3
b) “123”
c) “CBSE”
d) K=[1,2,3,4]
KVS ZIET MYSORE 138
12 Write the output of the following
A,B=10,20
A,B=B,A
print(A.B)
13 To print the following patterns using multiple print commands
*
**
***
****
*****
14 Write program to generate the following output
5 10 15, 20…..100
15 Rewrite the following by correcting the errors
Sname=int(input(“Enter Name”))
M=int(input(“Enter Mark”)
if M>33
print(“Pass”)
otherwise:
print(“Fail”)
4 Mark Questions
1 Define the following terms
a) Identifiers : A token is the smallest individual unit in a python program.
All statements and instructions in a program are built with tokens
b) Keywords
c) Expression
d) Tokens
2 Write a program to enter Marks in 5 subjects, Calculate and display total and
average marks
3 Create a list in Python of children selected for Sports with following names
Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik
Perform the following tasks on the list in sequence-
• Print the whole list
• Display the name “Vikram” from the list
• Add the name “Jay” at the end
• Remove the item which is at the second position
4 Write a program to calculate Area and Perimeter of a rectangle
KVS ZIET MYSORE 139
5 Write a program to print sum of first 10 natural numbers

ANSWERS TO QUESTIONS

1 mark Questions
1 Who developed Python Programming Language?
e) Wick Van Rossum
f) Rasmus Lerdorf
g) Guido Van Rossum
h) Niene Stom
2 In Python, which of the following characters is used to create single line comment
e) //
f) #
g) !
h) /*
3 An identifier cannot start with a ________
e) Number
f) Character
g) Underscore
h) None of the above
4 ______________ has a specific meaning in python program
e) Constant
f) Variable
g) Keyword
h) Identifier
5 Write the output of the following python statement
print(10//3)
e) 3
f) 3.33
g) 1
h) 0
6 Which of the following is the valid Python file extension?
e) . python
f) . pl
g) . py

KVS ZIET MYSORE 140


h) . p
7 Numbers with fractions or decimal points are called ________ datatype.
e) Integer
f) String
g) Float
h) None of the above
8 _______is an ordered sequence of letters/characters. They are enclosed in
single quotes (‘ ’ ) or double (“ ”).
e) String
f) Integer
g) Float
h) None of the above
9 ___________ are a sequence of values of any type, and are indexed by integers.
They are immutable and enclosed in ().
e) String
f) Lists
g) Tuples
h) All of the above
10 _________ function is used to display given output in python.
e) printf()
f) print()
g) scan()
h) None of the above
11 _________ function is used to take input from the user in python.
e) input()
f) insert()
g) store()
h) None of the above
12 The data type of 14.5 is __________
e) int
f) float
g) string
h) list
13 ___________ operator gives the remainder in Python.
e) %
f) /

KVS ZIET MYSORE 141


g) //
h) *
14 __________ operator is used to find the square of a number
e) ^
f) *
g) **
h) //
15 What does the following code print?
if 4 + 5 == 10:
print("TRUE")
else:
print("FALSE")
e) TRUE
f) FALSE
g) None of them
h) TRUE FALSE
16 What will be the datatype of following variable ?
A= “100”
e) int
f) float
g) string
h) list
17 Smallest element of python coding is called ______
e) Identifiers
f) Tokens
g) Keywords
h) Delimiters
18 Find the invalid variable among the following:
e) 1st_place
f) my_place
g) _first
h) Fun
19 T=[10,20,30,40] is a type of which datatype in python
e) int
f) string
g) list

KVS ZIET MYSORE 142


h) tuple
20 The _________ mode of python gives instant result of typed statement
e) Interactive mode
f) Script mode
g) Combination of interactive and script mode
h) All of these
2 mark Questions
1 What is the Difference between Interactive mode and script mode?
Ans Interactive mode is where you type commands and they are immediately
executed. Script mode is where you put a bunch of commands into a file
(a script), and then tell Python to run the file.
2 What are the basic datatypes in Python?
Ans The basic datatypes are
int – to represent integers
float - to represent floating point numbers
string – to represent sequence of characters
Boolean – to represent True or False
list- to represent collection of elements in [ ]
tuple – to represent collection of elements in ( )
dictionary – to represent the elements as key and value pairs in { }
3 What is a variable?
Ans A Python variable is a reserved memory location to store values
Eg: V=10, here V is variable
4 What are the arithmetic operators in Python?
Ans + for addition ( eg: print(5+5) gives 10
- for subtraction( eg: print(5-4) gives 1

KVS ZIET MYSORE 143


* for multiplication ( eg: print(5 * 4) gives 20
/ for division ( eg: print(7/2) gives 3.5
// for floor Division (eg: print(7//2) gives 3
% for reminder (eg: print(7%2) gives 1
** for Exponentiation (eg: print(3**2) gives 9
5 What are lists in python?
Ans Lists are mutable datatypes in python which can be used to store elements within
square brackets [ ]
Eg: L=[1, 3.5, “New”, [1,2,3] ]
6 What will be out of the following?
for I in range(1,10,2):
print(I)
Ans 1
3
5
7
9
7 What does the following code print?
if 4 + 5 == 10:
print("TRUE")
else:
print("FALSE")
Ans FALSE
8 L=[10, “New”, 34.5,30,40]
print( L[1])
L[2]=50
print(L)
Ans New
[10, 'New', 50, 30, 40]
9 What will be the output of the following
print ("hello")
print("Class9 \nArtificial Intelligence")

KVS ZIET MYSORE 144


Ans hello
Class9
Artificial Intelligence
10 State True or False
c) Python is case sensitive programming language
d) A variable’s value once assigned cannot be changed
Ans a) True
b) False
11 Identify the datatype in the following
e) 15.3
f) “123”
g) “CBSE”
h) K=[1,2,3,4]
Ans a) float
b) string
c) string
d) list
12 Write the output of the following
A,B=10,20
A,B=B,A
print(A,B)
Ans 20 10
13 To print the following patterns using multiple print commands
*
**
***
****
*****
Ans print(“ * ”)
print(“ * *”)
print(“* * *”)
print(“* * * *”)
print(“* * * * *”)
14 Write program to generate the following output
5 10 15, 20…..100
Ans # Program to generate the given series of numbers

KVS ZIET MYSORE 145


for I in range(5,101,5):
print(I, end= “ ” )
15 Rewrite the following by correcting the errors
Sname=int(input(“Enter Name”))
M=int(input(“Enter Mark”)
if M>33
print(“Pass”)
otherwise:
print(“Fail”)
Ans Sname=input(“Enter Name”)
M=int(input(“Enter Mark”))
if M>33:
print(“Pass”)
else:
print(“Fail”)
4 Mark Questions
1) Define the following terms
a) Identifiers
b) Keywords
c) Expression
d) Tokens
Ans a) Identifier: A token is the smallest individual unit in a python program
b) Keywords: Keywords are words that have some special meaning or
significance in a programming language. They can’t be used as variable
names or function names
c) Expression: an expression is a combination of values, variables, and
operators that evaluates to a single value
d) Tokens: It is the smallest unit of a program
2) Write a program to enter Marks in 5 subjects, Calculate and display total and
average marks
Ans # Program to calculate total and average marks
m1 = int(input("Enter first subject marks: "))
m2 = int(input("Enter second subject marks: "))
m3 = int(input("Enter third subject marks: "))

KVS ZIET MYSORE 146


m4 = int(input("Enter fourth subject marks: "))
m5 = int(input("Enter fifth subject marks: "))
avg = (m1 + m2+ m3+ m4 + m5) / 5;
print("Average Marks =", avg)
3) Create a list in Python of children selected for Sports with following names
Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik
Perform the following tasks on the list in sequence-
• Print the whole list
• Display the name “Vikram” from the list
• Add the name “Jay” at the end
• Remove the item which is at the second position
Ans Sports=[ “Arjun”, “Sonakshi”, “Vikram”, “Sandhya”,” Sonal”, “Isha”, “Kartik” ]
print( Sports)
print(Sports[2])
Sports.append(“Jay”)
Sports.pop(2)
4) Write a program to calculate Area and Perimeter of a rectangle
Ans length = int(input("Enter the length of the rectangle: "))
width = int(input("Enter the width of the rectangle: "))
area = length * width
perimeter = 2 * (length + width)
print("The area of the rectangle is:", area)
print("The perimeter of the rectangle is:", perimeter)

5) Write a program to print sum of first 10 natural numbers

Ans # Program to find sum of first 10 natural numbers


sum = 0
for i in range(1, 11):
sum = sum+ i
print(sum)

KVS ZIET MYSORE 147

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