[go: up one dir, main page]

0% found this document useful (0 votes)
15 views5 pages

Internal Two QB

The document covers fundamental concepts of Python programming, including definitions of variables and constants, data types, lists, tuples, operators, expressions, and the use of the 'import' statement. It also discusses flow control statements, looping constructs, recursion, string handling functions, and the immutability of strings. Additionally, it provides examples and exercises related to these topics.
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)
15 views5 pages

Internal Two QB

The document covers fundamental concepts of Python programming, including definitions of variables and constants, data types, lists, tuples, operators, expressions, and the use of the 'import' statement. It also discusses flow control statements, looping constructs, recursion, string handling functions, and the immutability of strings. Additionally, it provides examples and exercises related to these topics.
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
You are on page 1/ 5

GE3151 - PROBLEM SOLVING AND PYTHON

PROGRAMMING

Unit-II
PART A

1. Define Variable and Constant.


Variable
Variable is temporary storage location. We can change any time at the time of execution.
Ex: a = 23
a = 78
print(a) # 78 (Last value only store it and previous value erase it)
Constant
Constant is a fixed value. We cannot change at the time of execution.
Ex: PI = 3.14 (That value cannot change it, is a fixed one)
2. List the data types in Python.
Data Types in Python is classified into two types:
a. Scalar Data Type (Assigned for the one value) int, float, complex,
string and boolean
b. Vector Data Type (Assigned for the more than values)
List, Tuples, Set and Dictionaries.

3. Define list. Give example.


List is an ordered sequence of items. Python knows a number of compound data types,
used to group together other values. It can be written as a list of comma-separated values (items)
between square brackets. List items need not all have the same type.
Eg: >>> a = [’Ram’, ’Sita’, 100, 123.4]

4. What is tuple? Give example.


Tuple is an ordered sequence of items same as list.The only difference is that tuples are
immutable. Tuples once created cannot be modified. It is defined within parentheses () where items
are separated by commas.
eg: tup1 = ('physics', 'chemistry', 1997, 2000)
5.What are the operators in python?
Python Operators
i. Arithmetic operators. ii.
Assignment operators. iii.
Comparison operators. iv.
Logical operators.
v. Bitwise operators.
vi. Special types of operators
1. Identity operators.
2. Membership operators.
6. What is meant by expression in python?
A combination of operands and operators is called an expression. The expression in Python
produces some value or result after being interpreted by the Python interpreter.
Expression is classified into two types:

1. Unary expression (x = x + 1 or x += 1)
2. Binary expression (c = a + b)

7.What is the use of ‘import’ in python?


The import keyword is used to import the definitions inside a module to another module or
the interactive interpreter in Python.
Python provides two ways to import modules:
Eg1:
>>> import math
>>> print(math.pi)
3.14159265359
Eg2:
>>> from math import pi
>>> print(pi)
3.14159265359
‘’’
PART-B
1. Briefly explain the operators and types . Give a suitable example in python
2. Write the illustrative program of distance between two points and swap the values of two variables.
3. Explain on tuple assignment

UNIT-III

PART-A

1. List some flow control statements of python.


 if
 if-else
 if-elif-else
 Nested conditionals
2.What is looping? List some looping statements of python.
Looping is the process of executing a set of statements again and again till a condition is true. The
looping statements in Python are:
 while loop
 for loop
3.Write the syntax for ‘for loop’ and ‘while loop’.
Syntax for ‘for’ loop: for val in sequence:
Body of the loop
Syntax for ‘while’ loop:
while testexpression:
Body of the
loop
4.What is the use of ‘pass’ statement?
Using a pass statement is an explicit way of telling the interpreter to do nothing. Eg: def bar():
pass
If the function bar() is called, it does absolutely nothing.
5.Differentiate ‘break’ and ‘continue’ statement.
When a break statement is encountered inside a loop, the loop is immediately terminated and the
program control resumes at the next statement following the loop.
The continue statement works somewhat like a break statement. Instead of forcing termination, it forces
the next iteration of the loop to take place, skipping any code in between.
6.Define ‘recursion’ with example.
The process in which a function calls itself directly or indirectly is called recursion and the
corresponding function is called as recursive function.
Eg: def factorial(n):
if n == 1: return
1
else:
return n * factorial(n-1)
7. List few string handling functions in python.
• s.captilize() – Capitalizes first character of string
• s.count(sub) – Count number of occurrences of sub in string
• s.lower() – converts a string to lower case
• s.upper()– converts a string to upper case
• s.split() – returns a list of words in string
8. State any 4 boolean methods supported by string module in python.
• s.isalpha() – Returns true if string s contains only alphabets
• s.islower() - Returns true if string s is in lowercase
• s.isupper()- Returns true if string s is in uppercase
• s.isnumeric()-Returns true if string s contains only numbers
• s.isspace()-Returns true if string s contains only whitespaces
9. Strings are immutable. Justify
Strings are immutable, which means we cannot change an existing string. But a new string can be created from
the variation on the original string.
Ex:
a='python'
a[0] = 'k'
print(a) Output
Error
10. Write a Python program to reverse a given string. a='python' b=a[::-1] print(b)
Output nohtyp
11. Mention the use of slice[:] operator in lists.
Subsets of lists can be taken using the slice operator with two indices in square brackets separated by a
colon ([] and [m:n]). A range of items in a list can be accessed using the slicing operators
Ex:
L=[1,2,3,4,5]
K=L[2:]
print(K)
Output
[3,4,5]

PART B
1. Explain the if, if-else, if-elif-else and nested conditional constructs in Python with suitable example.
2. Explain while loop, for loop, break and continue statements in Python with suitable examples.
3. Explain the various string handling functions in python with suitable example.
4. What is the function?Explain the role of function call and function definition with example?
5. Explain type of arguments in python?
6. i)Write a program to find GCD of two numbers? ii)Write a python program to find the square root
7. Explain in detail about list as array
8. Write a program to find the factorial of the given number with recursion?

You might also like