Assignment 2
Assignment 2
Q.1) Define a function. Explain function definition and function call with an example.
Q.2)Differentiate between Local & Global variable. Write a python program to demonstrate
difference between local and global variable.
iii)Default arguments
Programs:
1) Write python program using function to find greatest of three numbers by passing
numbers as argument..
2) Write python program using lambada function to find whether number is odd or even.
3) Write a python program to display tables from 1 to 10 using formatting character.
4) Write a program to swap two numbers using a function
5) Write program using lambda function which adds 10 th the number passed in as an
argument and print the result?
String
Q.4) Write a program to count the number of characters and words in the given string.
i) Print (s[1:9])
Q.11) Write python, program to find whether a given character is present in a string or not. In
case it is present print the index at which it is present. Do not use built in string method.
Q.12) Write a python program to check whether a given string starts with specified character.
1.print(s[:11])
2.print(s[::-1])
3.print(s[“And” not in s)
4.print(s[4])
5.prints[0:10])
Q.19) Write Python Program to display a string and count character in the string using a loop?
Q.2) Write a python program that uses class to store exam number and marks of four subjects.
Use list to store the marks of four subject
Q.3) Explain following Terms : i) Data Abstraction & Encapsulation ii) Polymorphism
Q.4) Write a python program to create class car with two attributes name & cost. Create two
objects and display information
Q.7) Write a program to create a class ‘Employee’ with two attributes. Display the details of two
employees?
File Handling
Q.7)Write a python program that counts the number of tabs and new line characters in a file
Q.9)Write a program to read first 10 characters from the file and display it
Q.10)Write a python program to display current directory, create directory and remove created
directory
Q.11) Write a python program that reads data from one file and write into another file and line
by line.