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

Python Imp

Uploaded by

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

Python Imp

Uploaded by

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

Python Programming (S. Y.B.Sc.

- | P
Programs:
understood
The
entirely by meaning
of a
analysis of thecomputer
program is unambiguous and literal.
tokens and structure,
(Semai
and can h
First, remember that
languages, formal languages are much more condensed
not a good ideato longer to read them. Also, the structure is veryimportant, sothanit is natura
so it takes
read
from top to bottom, left to right. Instead, learn to parse the
your head,
identifying usualyn
Small errors in spellingtheandtokens and interpreting the structure. Finally, the details progranmatter
in apunctuation,
can make a big which you can get away with in natural
difference
1.9 THE
DIFFERENCE BETWEEN
formal language.
BRACKETS, PARENTHESES AND BRACES
languags
Brackets ]:
define mutable Generally
data typesbrackets
are used to index into an array. It also
okup/slicing.() : such as lists, list comprehensions and for indexiusedng to
loParenthesis
Parenthesesand areto used for two purposes: to control the of
Operationsit in an expression,
Python is used to define supply parameters to a order
function calls and other syntax. tuples, order of constructor or method. In
operations, generator expressions,
Braces {}:The braces
generally are used to group
contents of class or interface are enclosed in
statements in if statement, a loop, statements and declarations. The
braces. Braces are used
used to specify the scope of or other control to
used to create logical structures. It means group the
block of
statements. In python the braces are
dictionaries or sets. braces are also
. Write short note on QUESTIONS
2. Python and
Write a note on Python and its ways to use Python
k3 Explain compiler and history. interpreter.
Give features of interpreter.
5. Python,
Explain debugging and error types in
6.
Write short note on formal and Python.
Give the difference natural languages.
between Brackets, Parentheses and
Braces.
hothing but selt-describing text that helps programmer to
information about code block. With you can remind yourself what a
Condit

pPorton of the code does and make yourcomments,


code more accessible to other developers,
Since comments are written inside a file that is spy
way to determine that the text you going to be executed, Python need
write is a comment, and not a command that
executed. Youcan mark a text as a comment in two ways :
1. The hash-mark sign (#) - Text that
needst
comment and will not be executed. appears after the # sign will be defined
Ex.:
# This is a comment.
prìnt ('Hello world!") # This is another comment.

2.
The three double quotes( ) - If you need to comment out a longer multiline
text,y
can use three double quotes. Python will treat alltext inside the three quotes as a comment
Ex.

This is our first program.


It prints the text Hello world! 3.1

print ("Helo world!") bas


sta
3.1
QUESTIONS exe
1. Write short note on values and types in Python. Sy
Write short note of variables and naming in Python
3 List and explain any 10 keywords in Python. ¥
R Write short note on Python Data Types.
5 How toachieve type conversion in Python?
6. Explain Operators in Python with suitable example.
7. How to achieve input in Python?
BExplain types of comments in Python.
print(i)

OUTPUT
0
1
3

The pass statement : It is used when a statement is


do not want any command or code to required syntactically but you
execute. The pass statement is a null operation;
nohing happens when it executes. The pass is also useful in
willeventually go, but has not places where your code
Syntax : been written yet.
pass
Ex,

#PT.3.14 Program to use of pass


s= [11,13,8,22,27] statement.
erminate loop define for iin s:
if i==8:
pass

print("Middle of the list")


print(i)
OUTPUT
11
13
Middle of the list

22
27

Write short note on conditional QUESTIONS


Write short note on looping statements
in Python.
2
3. statements in Python.
How to use controlstatements in Python.
part of the Write a short program to
loop demonstrate use of Conditional Statements.
Ombination with Write a short program to
6.J Write a short program to demonstrate
use of Looping Statements.
demonstrate use of Control Statemnents.
unCt this
M in whi
ofiims
Reading the pr
Downey" is "leap of lal that itwill work. In w
value
eturn B.
Suggested by "Allenmath built in functions we know
We trust it and use it and it
default
in functions.
people already used it
use
code. When wefunction bodies as they are built and many
examined the for us functions. We know
functions are written by developers own Written
as these trust happens in case
of our
hesitation.
The same thing of exactiy and we call it without any insttead
what our code will do
When you get to the recursive call,
recursive programs. callworks.
Smeaningfulandexits. The sane is true of
execution, you should assume that the recursive
Tollowing the flow of finist
the function works correctly when you haven't
that
en calls
itselfto continue Its a bit strange to assume
writing it, but that's why it's called a leap of faith!

4.19 CHECKING TYPES


raises the error. If we want
T We are using the factorial function for floating point, it uncti
acnieve Tactorial with floating point numbers then we need to write it as user defined
and generalized it to achieve the results.
Before calling any function we need to check the type of its argument For this Pytho
introduce built in function isinstance()to verify the type of the argument It Returns
Boolean value stating whether the object is an instance or subclass of another object.
Syntax:
isinstance (object, classinfo)
where
object: Required. An object instance.
classinfo: Required. Aclass, type or a tuple containing classes, types or other tuples.
Ex.
>>> isinstance('a', int)
unction. False

QUESTIONS
1. Write a short program to demonstrate type
conversion in Python.
2. Explain any 5 math functions in Python in detail.
3. How todefine and access the
function in Python?
4. Write a
short program todemonstrate the use of
(5.) What is import? Explain ways of importing in parameterized function in Python.
6. Explain the difference between Python.
import module and form module.
( Write a short program to
8. Write
demonstrate use of function returning value.
short note on incremental development.
(9 Write ashort program to
demonstrate use of function recursion.
quotation markS.
lowercase (r) or uppercase (R) and
must be placed immediately preceding
thefirst quote mark.

Ex.:
#Pr.5.10Program to string concatenation (string addition)
s='RSADT"
t='AM"
for iin s:
print(i+t)

OUTPUT
RAM
SAM
AAM
DAM
TAM

Ex.
#Pr.5.11 Program to string
stl ="madam" palindrome
st2 =st1[:-1]
if st1==st2:

print("String is palindrome")
else:

print("String isnot palindrome")


OUTPUT
String is palindrome

1.
Demonstrate use of string QUESTIONS
The
strings in Python are operations with the help of s
3 Explain any five built in immutable. Justify. suitable
functions that are used with strings. program.
4.
Explain the string operations with help of different
5,, Explain the use of in and not
operator using operators.
strings with help of:
small suitable
program.
Athon Prgnamming(SYRS

OUTPUT
Sorted tist (in Desc): u, o',. 'e', 'a]
st.count(27): 1
len(st): S
min(st): 8
max(st) : 27
st.insert(2,-1): (13, 22,-1, 8, 27, 11]|
st.append(4): (13,22, -1, 8, 27, 11, 4)
st.index(8): 3
st.remove(8): (13, 22, -1, 27, 11, 4]
st.reverse(): (4, 11, 27,-1, 22, 13)
st.sort( ): F1,4 11, 13, 22, 27)
st.pop( ): -1, 4, 11, 13, 22, 27)

QUESTIONS
What are lists? How to define and access the elements of list.
Lists in Python are mutable. Justify.
3. How totraverse and delete the elemènts in the list?
Write short note on built in listoperators.
Explain built list functions and methods.
76
Python Programming (S.Y.B.Sc. - LT)|
9.
values(0:Thismethod returns list of dictionary values. (Sem-
Syntax :mydict.values()
Ex,:
>>> d2={'Name': "Tushar,'Age': 34, 'Class': 'First'}
>>> print ("Values:",
list(d2.values( ))
Values: Tushar', 'First', 34]

QUESTIONS
Write short note on tuple in Python.
What is tuple? How create and access it?
3.
Explain indexing, negative indexing and slicing with respect to tuples.
4. Write short note on tuple assignment and
5: Explain basic tuple returning the value.
6. Write
operations.
short note on built in tuple functions.
What is dictionary? How create and access it?
8.
Explain the properties of dictionary keys.
9. Write short note on operations in
dictionary.
J0. Explain built in dictionary functions.
L, Explain built in dictionary methods.
9
In Python,users can define such exceptions by creating a new class. Thie
has to be derived, either directly or indirectly, from
exceptions are also derived from this class.
Exception class.
Following program will ask the user to enter a number and guess
correctly: a
Most eRceyk
of the

stored
Ex.
# Pr.8.24 Python program to user define exception
class demo(Exception):
pass

val =int(input("Enter the number "))


try:
if val!=18:
raise demo
except demo:
print("Exception raised value no matched")
else:

print("value matched")
OUTPUT
Enter the number5
Exception raised value no matched
In above example we have
This is the standard way to defined a class called demno which raised by
define user-defined our progra
exceptions in Python programming.
1.) What is file? What are its QUESTIONS
2. Write short note
operating modes?
on file object attributes and file
3 Write a short methods.
program to deal with text file in Python.
4. What is
directory? Which methods are available to deal with
Write a short program todeal with directories in Python. directories in Pvthon?
What is Exception? List and explain any five built in
Write short note on exception handling mechanism inExceptions
Python.
in Python.
Write short note on Exception with arguments and
user defined
9. Write a short program to demonstrate Exception Handling in exception
Python.
S=STO
s.show( )
ST.sdemo()

OUTPUT
Hello World
Hello

of
PE
to arguments
10.13 POLYMORPHISM
functions or methods can be applied
type of the arguments differentwhichtypes,a
to

they
Polymorphic
can behave differently depending on the like int, float, char and
behaves they
stringfunction
example functionshow()
below
applied. In
Ex.
polymorphism
#Pr.10.19 Program touse
def show(s):
11.1
print("s: "s)
M
proce
show(11)
progr
show("Vedu") paral
show(1.2) Pythc
show('y')
inde
OUTPUT shar
S: 11 exec
S: Vedu the t
S: 1.2 This
S: y
11.

QUESTIONS po
1. What is Object Oriented Programming? Explain the concepts of 00P in
2. Write short note on class in Python. short.
3 List and explain built in class
attributes. Give
Write a short program todemonstrate use of example use.
of
4.
Write a short program to inheritance.
6.
demonstrate use of
Explain the concept of method overriding in multiple inheritance.
7. Explain Data Hiding, Data class with suitable example.
Encapsulation and static methods.
tm_min=56, tm_sec=49,tm_ wday=0, tm_yday=46, tm_isdst=0) mh0u
time.localtime( ): %s time.struct_time(tm_year=2017, tm_mon=5.
tm_hour=15, tm_min=36, tm sec=18, tm_wday=6, tm _yday=148, tm_isdst
May 28 2017 10:13:38
time.time(): 1495965978.937082

time.struct_time(tm_ year=2017, tm_mon=5, tm_mday=Z8, tm_hour=15,


tm_sec=18, tm_wday=6, tm_yday=148, tm_isdst=0) tn min=
Sun May 28 15:36:18 2017

tuple : time.struct_time(tm_year=2017, tm_mon=5, tm_mday=28,


tm_min=0, tm_sec=0, tm_wday=6, tm yday=148, tm_isdst=-1) tm_houre,
Start:Sun May 28 15:36:18 2017
End: Sun May 2815:36:24 2017

QUESTIONS
1.)What is multithreading? Write short note on
2.
thread module.
Explain creation of thread with suitable example.
3. Write short note on thread and Threading
modules.
How to synchronize the thread? Explain in detail.
5 Write short note on
Pythons Multithreaded priority queue. Give example.
6 What are module? How use it? What are its
7 How to create module? Explain
advantages?
with example.
Explain math module with its any five functions.
9. Demonstrate the use of math module functions with suitable example.
10. Explain time module with its any five functions.
11. Demonstrate the use of time module
functions with suitable example.
12. Explain random module with its any five functions.
13 Demonstrate the use of
randommodule functions with suitable example.
152
Python Programming (S.Y.B.Sc.-))(Sem.
QUESTIONS
What is GUI? Explain its advantages.
Explain creating GUl in Python with tkinter?
3.
Write note on standarddimension attributes of tkinter module.
+. Explain in details the standard colour attributes of tkinter module.
5.
Write note on standard font attributes of tkinter module.
6.
Write short note on anchor and relief attribute in Python GUI.
Explain creation of label widget with small example.
Writeshort note on checkbutton widget.
9. Write short note on button widget.
10. Explain creation of radiobutton widget with small example.
1 Explain frame with example.
12. Write a detail note on canvas widget.
13.)Write a detailnote on list widget.
14. Write short note on menu and menubutton.
15.)Explain Entry and text widget with small example.
16. Write short note on scale and scrollbar widget.
17. Write short note on spinbox widget. Give example.
18. Write short note on PanedWindow and LabelFrame.
(19./What is message box? What are its types?
20. Build asimple GUl application with demonstrating event handling of multiple
widgets.

You might also like