Slip 3
Slip 3
import math as m
n = int(input("Enter a number:\n"))
if n%3==0:
print("%d is divisible by 3"%n)
elif n%5 == 0& n%10==0:
print("%d is divisible by 5 and 10"%n)
2. Repeat the following string 11 times using the string operator on Python.
a. LATEX
b. MATLAB
repeated_latex = "LATEX" * 11
print(repeated_latex)
repeated_matlab = "MATLAB" * 11
print(repeated_matlab)
sum = 0
for i in range(1, 31):
sum += i
print(sum)
import numpy as np
a=np.identity(10)
b=np.zeros([7,3])
c=np.ones([5,4])
print(a,b,c)
3. Generate all the prime numbers between 1 to 100 using Python code.
Q.Write Python program to estimate the value of the integral fo sin(x)dx using
Simp- son's (1/3)rd rule (n=6).
# Finding sum
integration = f(x0) + f(xn)
for i in range(1,n):
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f(k)
else:
integration = integration + 4 * f(k)
return integration
# Input section
lower_limit = float(input("Enter lower limit of integration: "))
upper_limit = float(input("Enter upper limit of integration: "))
sub_interval = int(input("Enter number of sub intervals: "))
Q. write the python program to estimate the value of integral 1/(1+x) using
trapezoidal rule (n=5)
# Finding sum
integration = f(x0) + f(xn)
for i in range(1,n):
k = x0 + i*h
integration = integration + 2 * f(k)
return integration
# Input section
lower_limit = float(input("Enter lower limit of integration: "))
upper_limit = float(input("Enter upper limit of integration: "))
sub_interval = int(input("Enter number of sub intervals: "))