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

Chapter 6

Chapter 6 provides an introduction to Python, covering its history, features, and modes of operation. It discusses Python's advantages and limitations, as well as practical examples and multiple-choice questions to test understanding. The chapter emphasizes Python's versatility as a cross-platform, open-source, and object-oriented programming language.

Uploaded by

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

Chapter 6

Chapter 6 provides an introduction to Python, covering its history, features, and modes of operation. It discusses Python's advantages and limitations, as well as practical examples and multiple-choice questions to test understanding. The chapter emphasizes Python's versatility as a cross-platform, open-source, and object-oriented programming language.

Uploaded by

kingsss99909
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Chapter 6: GETTING STARTED WITH PYTHON

Q1. When was Python released?


Ans- Python was released in February 1991.

Q2. Who developed Python?


Ans- Python was developed by Guido Van Rossum.
[Link] two languages contributed to Python as a Programming Language?
Ans- ABC language and Modula 3.
Q4. Is Python an Object Oriented Language?
Ans- Yes, Python is an object oriented language.
Q5. Python got its name from which show?
Ans- Python got its name from famous BBC comedy show “Monty Python’s Flying Circus”.
Q6. “Python is an interpreted language‟. What does it mean to you?
Ans- It means that the Python installation interprets and executes the code line by line at a time.
Q7. What does a cross platform language mean?
Ans- it means a language can run equally on variety of platforms-Windows, Linux/UNIX, Macintosh,
Supercomputers, Smart phones etc.
Q8. Python is a Free and Open Source language. What do you understand by this feature?
Ans- It means Python is freely available without any cost. Its source code is also available. One can modify,
improve/extend an open source software.
Q9. In how many ways, can you work in Python?
Ans-In two ways we can work in Python-
(i) Interactive mode
(ii) Script Mode
Q10. What is the difference between Interactive mode and Script Mode in Python?
Ans- In interactive mode, one command can run at a time and commands are not saved. Whereas in Script
mode, we can save all the commands in the form of a program file and can see output of all lines together.

Q11. What are the advantages of Python?


Ans- Advantages of Python are as follow:-
i. Easy to use OO Language.
ii. Expressive Language.
iii. Interpreted Language.
iv. It is complete.
v. Cross-Platform Language.
vi. Free and Open Source.
vii. Variety of Usage/ Applications

Q12. What are the limitations of Python?


Ans- limitations of Python are as follow:-
i. Not the fastest language.

Prepared By: Pulak Sir………………..


ii. Lesser Libraries than C, Java, Perl.
iii. Not strong on Type Binding.
iv. Not easily convertible.
Q13. Which of the following are not valid strings in Python?
(a) ‘Hello’ (b) “Hello” (c) Hello‘ (d) ‘Hello” (e) {Hello}
Ans- String (c) , (d) and (e ) are not valid strings.
Q14. Write Instructions in python to get the following result:
I am a student of ARPS Agartala
I live in Agartala
And I love Agartala.
Ans: >>> print("I am a student of ARPS Agartala \nI live in Agartala \nAnd I love Agartala\ ")

Q14. What is a cross-platform software?

Answer: A cross-platform software is a software that can run well on a variety of platforms
like Windows, Linux/Unix, Macintosh, etc.

Q15. What are advantages/disadvantages of working in Interactive mode in


Python?

Answer: Interactive mode is useful for testing code. We can type the commands one by one
and get the result of error immediately for each command. Disadvantages of Interactive
mode are that it does not save commands in form of a program and also output is
sandwiched between commands.

Q16. What are the advantages/disadvantages of working in script mode in


Python?

Answer: Script mode is useful for creating programs and then run the programs later and
get the complete output. It is not suitable for testing code.

Q17. Write instructions to get the following result :

Math is Fun so don't be resistant


Just learn the rules, the rules are consistent
And most important, you must be persistent !

Adding fractions, get common denominators.


Multiply by missing factors to get the denominators.
Add numerators only, NOT denominators.

Do it in both interactive mode and script mode.

Answer: Interactive Mode

>>> print("Math is Fun so don't be resistant")


Math is Fun so don't be resistant
>>> print("Just learn the rules, the rules are consistent")

Prepared By: Pulak Sir………………..


Just learn the rules, the rules are consistent
>>> print("And most important, you must be persistent !")
And most important, you must be persistent !
>>> print("")

>>> print("Adding fractions, get common denominators.")


Adding fractions, get common denominators.
>>> print("Multiply by missing factors to get the denominators.")
Multiply by missing factors to get the denominators.
>>> print("Add numerators only, NOT denominators.")
Add numerators only, NOT denominators.
>>>

Script Mode:

print("Math is Fun so don't be resistant")


print("Just learn the rules, the rules are consistent")
print("And most important, you must be persistent !")
print("")
print("Adding fractions, get common denominators.")
print("Multiply by missing factors to get the denominators.")
print("Add numerators only, NOT denominators.")

Output
Math is Fun so don't be resistant
Just learn the rules, the rules are consistent
And most important, you must be persistent !

Adding fractions, get common denominators.


Multiply by missing factors to get the denominators.
Add numerators only, NOT denominators.

Example 1: Write a program to store the names of three students and display
them.
name1 = "Aman"
name2 = "Sumit"
name3 = "Ananya"
print(name1)
print(name2)
print(name3)

OUTPUT:

Aman
Sumit
Ananya

Example 2: Write a program to display the sum of two numbers.


num1 = 20
num2 = 30

Prepared By: Pulak Sir………………..


s = num1 + num2
print(s)

OUTPUT:

50

Multiple Choice Questions:

Q1. Python is a/an .......... language.


a. High level ✓ b. Object oriented ✓ c. procedural d. difficult
Q2. Python uses a/an .......... to convert source code to object code.
a. Interpreter ✓ b. Compiler
c. Combination of Interpreter and compiler d. Special virtual engine
Q3. Python code can run on a variety of platforms, it means Python is a .......... language.
a. Graphical b. Cross-platform ✓ c. independent d. all of these
Q4. Python programs are typed in
a. Interactive mode [Link] mode ✓
c. A combination of interactive and script modes d. All of these
Q5. The .......... mode of Python gives instant result of typed statement
a. Interactive mode ✓ b. Script mode
c. Combination of interactive and script modes d. All of these
Q6. Which of the following is not correct about python?
a. Python is an open source language.
b. Python is based on ABC language.
c. Python is developed by Guido Van Rossum
d. None of the above
Ans. d. None of the above
Q7. Smallest element of of python coding is called __________
a. Identifiers b. Token c. Keywords d. Delimiters
Ans. b. Token
Q8. Which of the following is not a token?
a. // b. “X” c. ## d. 23
Ans. c. ##
Q9. Write the output of the following code:
x=2
x=5
x=x+x
print(x)
a. 7 b. 4 c. 10 d. Error
Ans. c. 10
Q10. Write the output of the following code :
x=2
y=3
x+y+5
print(x+y)
a. 10 b. 5 c. Error d. None of the above
Ans. b. 5
Q11. Which of the following symbol is used to write comment?
a. ? b. // c. # d. **

Prepared By: Pulak Sir………………..


Ans. c. #
Q12. Writing comments is mandatory in python programs(T/F)
a. True b. False
Ans. b. False
Q13. Each statement in python is terminated by ___________
a. Semicolon(;) b. Colon(:) c. Comma(,) d. None of the above
Ans. d. None of the above

Q14. Write the output of the following:


print(‘Hello, world!’);print(“H”)
a. Hello world H b. Hello worldH c. Hello world d. Error

H
Ans. c. Hello world
H
Q15. _______ spaces should be left for indentation.
a. 3 b. 4 c. 5 d. 0
Ans. b. 4
Q16. What type of error is returned by the following statement?
def abc(a):
print(a)
a. ErrorIndentation b. IndentationError
c. SpaceErrord. d. No error in the given statement
Ans. b. IndentationError
Q17. return statement is mandatory in function definition.(T/F)
a. True b. False
Ans. b. False
Q18. Which keyword is used to define a function in python?
a. def b. define c. new d. None of the above
Ans. a. def
Q19. Write the output of the following:
a=8
def abc(a):
print(a)
abc(7)
a. 8 b. Error c. No Output d. 7
Ans. d. 7
Q20. Statement below “function definition” begin with spaces called _________________
a. Indentation b. Condition c. Definition d. None of the above
Ans. a. Indentation
Q21. Which of the following is invalid variable name?
a. Sum1 b. Num_1 c. Num 1 d. N1
Ans. c. Num 1
Q22. Write the output of the following.
def abc():
print("abc")
a. abc b. Error c. 0 d. No Output
Ans. d. No Output
Q23. Python is case sensitive.(T/F)
a. True b. False
Ans. a. True

Prepared By: Pulak Sir………………..


Q24. Which statement will display square of number (n)
a. print(n * n) b. print([Link](n,2)) # math module is already imported
c. All of the above d. Only First
Ans. c. All of the above
Q25. What type of error is returned by the following statement?
print(eval(13))
a. SyntaxError b. TypeError c. ValueError d. No Error in this statement
Ans. b. TypeError

Programs:

Q1. WAP to Add Two Numbers.

# This program adds two numbers

num1 = 1.5
num2 = 6.3

# Add two numbers


sum = num1 + num2

# Display the sum


print('The sum of {0} and {1} is {2}'.format(num1, num2,
sum))

Q2. WAP in Python to Find the Square Root

num = 8

# To take the input from the user


#num = float(input('Enter a number: '))

Prepared By: Pulak Sir………………..


num_sqrt = num ** 0.5
print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))

Q3. Python Program to Calculate the Area of a Triangle

a = 5
b = 6
c = 7

a = float(input('Enter first side: '))


b = float(input('Enter second side: '))
c = float(input('Enter third side: '))

# calculate the semi-perimeter


s = (a + b + c) / 2

# calculate the area


area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)

Q4. Write a Python Program to Swap Two Variables.

# To take inputs from the user


x = input('Enter value of x: ')
y = input('Enter value of y: ')

# create a temporary variable and swap the values


temp = x
x = y
y = temp

Prepared By: Pulak Sir………………..


print('The value of x after swapping:',x)
print('The value of y after swapping:',y)

Q5. Write a Python program to find the area of a rectangle given that its
length is 10 units and breadth is 20 units.

#To find the area of a rectangle


length = 10
breadth = 20
area = length * breadth
print(area)

Output: 200

Q6. Write a program in python that inputs a student’s marks in three


subjects (out of 100)and prints the percentage marks

print('Enter the marks of three subject out of 100')


a=float(input('Enter the marks of first subject:'))
b=float(input('Enter the marks of second subject:'))
c=float(input('Enter the marks of third subject:'))

P=(a+b+c)/3
print('The percentage marks are:', P,'%')

Q7. Write a program to calculate simple interest.

P=float(input('Enter the principal amount in Rs.'))


R=float(input('Enter the rate of interest:'))
T=float(input('Enter the time in years:'))

SI=(P*R*T)/100

print('The simple interest is :', SI)

Q8. Write a program to read two numbers and prints their quotient and
reminder

a=float(input('Enter the dividend:'))


b=float(input('Enter the divisor:'))

Q=a//b
R=a%b

print('The quotient is:', Q)


print('The remainder is:', R)

Prepared By: Pulak Sir………………..

You might also like