Uploaded by Instagram Login

CE1-RollNo21530

advertisement
Fergusson College (Autonomous), Pune-4
Department of Computer Science M. Sc (Computer Science)-1,
Semester-I
CSC4104 Python Programming
Name: Vikram Anil Waykar
Roll no: 21530
Concurrent Evaluation-I
Q1. Write a program to read a specific line (for e.g. line 5) from the file and print
it.
obj=open("Mydata.txt","r")
line=obj.readline()
n=int(input("Enter the line number"))
if(n<=len(line) and n>0):
print(line[n-1])
else:
print("Line does not found")
Q2. Create a simple Calculator using functions. (Add, Sub, Div, Mult). Take input
from User for reading the numbers. Also, perform proper check for Division by
Zero or negative number..
def add(a,b):
return a+b
def mul(a,b):
return a*b
def div(a,b):
return a/b
def sub(a,b):
return a-b
print("1]Addition \t 2]Substraction \t 3]Multiplication \t 4]Division ")
ch=int(input("Enter your choice"))
a=int(input("Enter the first no:"))
b=int(input("Enter the Secound no:"))
def choice(ch):
switcher={
1:print("Addition:”, add(a,b)),
2:print("Substruction:",sub(a,b)),
3:print("Multiplication:",mul(a,b)),
4:print("Division:",div(a,b))
}
choice(ch)
Q3. Write a program to find the HCF and LCM of two numbers. Read
the number from the user.
def HCF(a,b):
if a>b:
min=b
else:
min=a
for i in range(1,min+1):
if(a%i==0 and b%i==0):
hcf=i
return hcf
a=int(input("Enter a number :"))
b=int(input("Enter a number :"))
if(a<0 or b<0):
print("Number should be > 0")
else:
hcf=HCF(a,b)
print("HCF is".format(a,b,hcf))
lcf=(a*b)/hcf
print("LCF".format(a,b,lcf))
Download