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

Python Basics: Data Types & Loops

The document provides an introduction to Python, covering its definition, key features, applications, and built-in data types. It includes fill-in-the-blank exercises and answers related to Python programming concepts such as loops, strings, and boolean values. Additionally, it presents sample code snippets for displaying the Fibonacci sequence, adding two numbers, swapping values, and generating a multiplication table.

Uploaded by

satyesh
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 views4 pages

Python Basics: Data Types & Loops

The document provides an introduction to Python, covering its definition, key features, applications, and built-in data types. It includes fill-in-the-blank exercises and answers related to Python programming concepts such as loops, strings, and boolean values. Additionally, it presents sample code snippets for displaying the Fibonacci sequence, adding two numbers, swapping values, and generating a multiplication table.

Uploaded by

satyesh
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

Chap.

3: Introduction to Python and Datatypes of Python

Q 1. Fill in the blanks:


1. Looping is also known as iteration statement.
2. Conditional statement cause the interpreter to jump from one part of the
program to another part based on some condition.
3. In If-elif-else statements, multiple conditions are tested.
4. The for loop is preferred when the number of iteration is fixed.
5. While loop allows the block of code to be executed till the condition is
true.
6. Platform independent means program written on software can be used on
any operating system.
7. Variables are containers for storing data values.
8. Equal sign (=) is used to declare a variable.
9. The print() function prints the specified message.
10. Assignment operator assign right hand side value to left hand side
variable.

Q 2. Answer the following questions:

1. What is Python?

Ans: Python is an interpreted, object-oriented, high-level programming language with


dynamic semantics. Python is a computer programming language often used to build
websites and software, automate tasks, and conduct data analysis. Python is a general-
purpose language, meaning it can be used to create a variety of different programs and
isn't specialized for any specific problems.

2. What are the key features of Python?

Ans: The following are the significant features of Python, and they are:

 Interpreted Language: Python is an interpreted language that is used to execute the


code line by line at a time. This makes debugging easy.
 Highly Portable: Python can run on different platforms such as Unix, Macintosh,
Linux, Windows, and so on. So, we can say that it is a highly portable language.
 Extensible: It ensures that the Python code can be compiled on various other
languages such as C, C++, and so on.
 GUI programming Support: It implies that Python provides support to develop
graphical user interfaces

3. What are the applications of Python?

Ans: The applications of Python are as follows:

 GUI-based desktop applications


 Image processing applications
 Business and Enterprise applications
 Prototyping
 Web and web framework applications

4. What are the built-in types available in Python?

Ans: The built-in types in Python are as follows:

 Integer
 Boolean
 Floating-point numbers
 Strings
 Built-in functions

5. Define String in Python?

Ans: String in Python is formed using a sequence of characters. Value once assigned to a
string cannot be modified because they are immutable objects. String literals in Python
can be declared using double quotes or single quotes.

6. What is a boolean in Python?

Ans: Boolean is one of the built-in data types in Python, it mainly contains two values,
which are true and false. Python bool() is the method used to convert a value to a boolean
value.

7. What is escape sequence?

Ans: It consists of two or more characters, where the first character is always the
backslash (\).They are used to print a non-printable characters such as Tab and Enter in
the output.
 ‘\t’ (horizontal tab): they are used to provide horizontal tab between arguments.
 ‘\n’ (new line): this add new lines between the arguments.

8. Define For loop

Ans: It is used to execute a set of statements repeatedly till the test condition is true. This
loop is preferred till the number of iteration is fixed. This is also known as fixed loop. It
is used when user want to execute code for fixed range. The for loop in python continues
until we reach the last sequence of statement.
Syntax:
• for <variable> in <sequence>
Or
• for <variable> in range (initial value, final value, step value)

9. What do you mean by infinity loop statement?

Ans: It is a kind of loop that runs endlessly because the test condition never comes false.
The infinity loop is created, when a user enters a condition that can never be met and thus
results in loop that never ends.

[Link] a program to display the Fibonacci sequence in Python?

Ans: # Displaying Fibonacci sequence


n = 10
# first two terms
n0 = 0
n1 = 1
#Count
x = 0
# check if the number of terms is valid
if n <= 0:
print("Enter positive integer")
elif n == 1:
print("Numbers in Fibonacci sequence upto",n,":")
print(n0)
else:
print("Numbers in Fibonacci sequence upto",n,":")
while x < n:
print(n0,end=', ')
nth = n0 + n1
n0 = n1
n1 = nth
x += 1
OutPut: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34

11. Write code to add two numbers.


Ans:
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')
sum = int(num1) + int(num2)
print('The sum two number is', sum)

12. Write code for swapping two numbers.


Ans:
x = input('Enter value of x: ')
y = input('Enter value of y: ')
x, y = y, x
print("x =", x)
print("y =", y)

13. Write python program to display multiplication table.


Ans:
num = 12
for i in range(1, 11):
print(num, 'x', i, '=', num*i)

You might also like