Вы находитесь на странице: 1из 4

Present the flow of execution for a while statement.

while condition:
true part statements
1.
.
.
normal statements
Write a Python program to accept two numbers and multiply two numbers and print the result.
a=int(input())
b-int(input())
print(a*b)
Differentiate Pass and Continue
Pass – Does nothing and proceed with the normal execution of next line with respect to the flow
Continue – Skips the current iteration and continues with the next iteration
Define recursion with example.
Recursion is a function that calls by itself repeatedly until the condition is true.
e.g. def fn( ):
2.
.
.
fn( )
Give the difference between Break and Continue statement.
Break – Stops the execution of the entire loop and the normal statement outside of the loop executes.
Continue - Skips the current iteration and continues with the next iteration
What are the types of parameters?
Actual Parameters – Values or variables passed in the function calling statement.
Formal Parameters – Values or variables passed in the function definition statement.
Write a Python program to accept two numbers and find the greatest and print the result.
a=int(input())
b-int(input())
3. if a>=b:
print(“a is big”)
else:
print(“b is big”)
Differentiate Local and global variables.
Local variables – variable that is declared inside a specific function and accessible to the function only
Global variables – variable that is declared outside of the function and accessible inside and outside the
function.

Give the difference between parameter and arguments.


Parameter is variable in the declaration of function.
Argument is the actual value of this variable that gets passed to function.
Relate string and List.
4. String – Group of characters or words enclosed between single or double quotes. It is immutable
List – Sequence of elements of any data type stored from the 0th position. It is mutable.
How to perform Slicing in List.
>> a=[1,2,3,4,5]
>>a[0:1]
[1]
>>a[:]
[1,2,3,4,5]
Define List comprehension.
A way to construct a list containing series of elements in an easy way. It applies expression to items in
each iteration.
>>> L=[x**2 for x in range(11)]
>>> L
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
What is a list? How lists differ from tuples.
List - Sequence of elements of any data type stored from the 0th position enclosed between square
5. brackets. It is mutable.
Tuple - Sequence of elements of any data type stored from the 0th position enclosed between normal
braces. It is mutable.
How to create a list in python? Illustrate the use of negative indexing of list with example.
>>a=[1,2,3,4,5]
>>a
[1,2,3,4,5]
>>a[-1]
[5]
>>a[-5]
[1]
Differentiate List and Dictionary.
List - Sequence of elements of any data type stored from the 0th position enclosed between square
brackets. It is mutable.
Dictionary – Elements in the dictionary are having keys and values in the format key:value. The values
can be accessed by means of keys only. Elements are enclosed between flower braces {}
Give a function that can take a value and return the first key mapping to that value in a
dictionary.
def pro(key):
print(a.get(key))
6. a={1:2,3:4.5,"hi":6,7.8:9}
b=list(a.keys())
print(b)
c=b[0]
pro(c)
Demonstrate with simple code to draw the histogram in python.
import matplotlib.pyplot as plt
from numpy.random import normal
gaussian_numbers=normal(size=1000)
plt.hist(gaussian_numbers)
plt.title(“Gaussian Histogram”)
plt.xlabel(“Value”)
plt.ylabel(“Frequency”)
plt.show( )
Find the maximum of list using predefined function.
a=[1,2,3,45]
print(“List is:”,a)
print(“Maximum in the list is:”,a.max( ))
What is a module? Give Example.
A module is a file containing Python definitions and statements. A module can define functions, classes
7.
and variables. A module can also include runnable code. Grouping related code into a module makes the
code easier to understand and use.
Define Errors and give its types.
Errors – Bugs in the program are called as errors and caused by the fault of the programmer. Major types
of errors are syntax error and run time error.
Write short notes on Files.
File is a named location on disk to store related information. It is used to permanently store data in a
non-volatile memory (e.g. hard disk). Since, random access memory (RAM) is volatile which loses its
data when computer is turned off, we use files for future use of the data.
Write a python script to display current date and time.
import datetime
8. now = datetime.datetime.now()
print ("Current date and time : ")
print (now.strftime("%Y-%m-%d %H:%M:%S"))
Write the built in exception handling functions.
Arithmetic Error - base class for those built-in exceptions that are raised for various arithmetic errors
such as :
OverflowError
ZeroDivisionError
FloatingPointError
Define Exception
An exception is an event, which occurs during the execution of the program that disrupts the normal
flow of the program. When the program raises an exception, then python must handle the exception
otherwise it terminates and quits.
Find the syntax error in the code given: While True: print (‘Hello World’)
9
No syntax error. The program runs and prints the “Hello World” indefinitely without stopping.
Write a python program that writes “Hello world” into a file.
fp=open("samplee.txt","w")
fp.write("Hello World")
fp.close()
Define Packages.
Packages are namespaces which contain multiple packages and modules themselves. They are simply
directories, but with a twist.
Each package in Python is a directory which MUST contain a special file called _ _init_ _.py
Define module.
A module is a file containing Python definitions and statements. A module can define functions, classes
10
and variables. A module can also include runnable code. Grouping related code into a module makes the
code easier to understand and use.

10
The above code prints the location of the files that are storing by default. The entire location up to the
folder “python35-32” will be printed as output. CWD – Current Working Directory
What are command line arguments?
Input can be directly sent as an argument.
10
When the program is running under command prompt then inputs can be passed directly in the
command and can be fetched using "sys" module.

Вам также может понравиться