0% found this document useful (0 votes)
3 views

Part B L5 Introduction to Python Q Ans

The document provides a series of questions and answers related to Python programming, covering topics such as interactive vs script mode, basic data types, variables, arithmetic operators, lists, and control structures. It includes examples of code snippets and expected outputs for various programming tasks. Additionally, it defines key programming concepts like identifiers, keywords, and expressions.

Uploaded by

shalypx
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Part B L5 Introduction to Python Q Ans

The document provides a series of questions and answers related to Python programming, covering topics such as interactive vs script mode, basic data types, variables, arithmetic operators, lists, and control structures. It includes examples of code snippets and expected outputs for various programming tasks. Additionally, it defines key programming concepts like identifiers, keywords, and expressions.

Uploaded by

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

L5- Introduction to Python

Answer the following


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
* 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

1|Page
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")
Ans
hello
Class9
Artificial Intelligence

10 State True or False


a) Python is case sensitive programming language
b) A variable’s value once assigned cannot be changed
Ans
a) True
b) False
11 Identify the datatype in the following
a) 15.3
b) “123”
c) “CBSE”
d) K=[1,2,3,4]
Ans
a) float
b) string
c) string
d) list

12 Write the output of the following

2|Page
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
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”)

16. 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

3|Page
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

17. 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: "))
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)

18. 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)

19. 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)

20. 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)
4|Page

You might also like