Cs Python Record
Cs Python Record
Cs Python Record
Output
Python program for void function with different function arguments
def add_numbers(num1=5, num2=6):
sum = num1 + num2
print("Sum: ",sum)
Output
Python Program to create and import a user defined module
sum.py
def add(a, b):
result = a + b
return result
import_example.py
import sum
a=int(input("Enter a value for a:"))
b=int(input("Enter a Value for b:"))
print(sum.add(a,b))
Output
Python Program for checking a number is divisible by another using Boolean function
Output
Python Program for Recursive function
def factorial(n):
if n == 1:
return n
else:
return n * factorial(n-1)
Output
Python Program for Leap of faith
def recursive_fibonacci(n):
if n <= 1:
return n
else:
return(recursive_fibonacci(n-1) + recursive_fibonacci(n-2))
Output
Python Program to check a number is palindrome or not using while loop
n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")
Output
Python program for searching the character position in a string
Output
Python program for search a String and count
print(count)
if count==0:
print ("Searching letter is not in the word"
Output
Python program to display multiplication table using for loop
Output
Python program to create, append and remove lists in python
Output
Python program to print the sub-list of a given list to the specified range
Output
Python program to demonstrate work with tuples
Output
Python Program to read and display the elements of a Dictionary
d={}
n=int(input("Enter the length:"))
for i in range(n):
k=input("Enter the Key:")
v=input("Enter the Value:")
x={k:v}
d.update(x)
print("The Dictionary:",d)
Output
Python program to compute the number of characters, words and lines in a file
file=open("sample.txt","r")
number_of_lines=0
number_of_words=0
number_of_characters=0
for line in file:
line=line.strip("\n")
words=line.split()
number_of_lines+=1
number_of_words+=len(words)
number_of_characters+=len(line)
file.close()
print("lines:", number_of_lines, "words:", number_of_words, "characters:",
number_of_characters)
sample.txt
The New College
Department of Computer Science
Chennai
Output
Python program to perform read and write operations on a file
Output
Python program for Exception Handling
def exception():
x=int(input("\nEnter the number1:"))
y=int(input("Enter the number2:"))
try:
z=x/y
except ZeroDivisionError:
print("Number2 Value should not be zero")
exception()
else:
print("The result is:",z)
exception()
Output