08 SubhasishBagchi Day1
08 SubhasishBagchi Day1
In [26]:
import math
s=(a+b+c)/2;
area=math.sqrt(s*(s-a)*(s-b)*(s-c))
if(area!=0):
if(area==0):
It is a Isosceles Triangle.
In [ ]:
2. Write a python to check the number is power of 3.
In [6]:
# Check the number is power of 3 or not---------
def isPower_of_Three(n):
if (n <= 0):
if (n % 3 == 0):
if (n == 1):
return False
num1 =int(input("Enter the number =")) # Taking input from user ------------
else:
In [ ]:
# 3. Write a python program to print the following patterns for n lines.
i)
**
***
****
*****
In [7]:
# 1st pattern
for i in range(n):
for j in range(n):
print("*", end="")
else:
print()
**
***
****
*****
In [ ]:
ii)
*****
****
***
**
In [8]:
# 2nd pattern
for i in range(n):
for j in range(n):
print("*", end="")
else:
print()
*****
****
***
**
*
In [ ]:
iii)
*****
****
***
**
In [9]:
n=5 # statically initialize the n -----------
for i in range(n):
for j in range(n):
print("*", end="")
else:
print()
*****
****
***
**
In [ ]:
iv)
**
***
****
*****
In [10]:
n=5 # statically initialize the n -----------
for i in range(n):
for j in range(n):
print("*", end="")
else:
print()
*
**
***
****
*****
In [ ]:
v)
*****
***
***
*****
In [11]:
# 5th pattern
for i in range(n):
for j in range(n):
print("*", end="")
else:
print()
*****
***
*
***
*****
In [ ]:
vi)
* *
** **
*****
** **
* *
In [12]:
# 6th pattern
for i in range(n):
for j in range(n):
print("*", end="")
else:
print()
* *
** **
*****
** **
* *
In [ ]:
vii)
***
*****
*******
*********
In [13]:
n=9 # statically initialize the n -----------
for i in range(n):
for j in range(n):
print("*", end="")
else:
print()
***
*****
*******
*********
In [ ]:
viii)
*********
*******
*****
***
In [14]:
n=9 # statically initialize the n -----------
for i in range(n):
for j in range(n):
print("*", end="")
else:
print()
*********
*******
*****
***
In [ ]:
4. Write a python program to evaluate the following series
In [15]:
# (i) S = 1 + 3 + 5 + 7 + ………… + N (Input N).
n=int(input("enter the range upto which you want to print : ")) # Taking input from user -----
s=0.0
for i in range(1,n+1,2):
s=s+i
In [16]:
import math # Import of math module -----------
n=int(input("enter the range upto which you want to print : ")) # Taking input from user -----
s=0.0
for i in range(1,n+1):
s=s+1/math.pow(-3,(i-1))
In [17]:
import math # Import of math module -----------
s=0
print (t)
s = s + t
Terms are :
1.0
-1.0
0.5
-0.16666666666666666
0.041666666666666664
Sum = 0.37500000000000006
In [21]:
import math # Import of math module -----------
i=1
term=x
sum1=x
while True:
term=(term*(-1)*x*x)/(2*i*(2*i+1))
sum1=sum1+term
i=i+1
if (math.fabs(term)<0.000000000000000000001): # using the fabs function for getting the absoulate vale of term--------------
break
print (sum1)
1.0000000000000002
In [ ]:
5. Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number.
In [22]:
num=int(input("Enter the number : ")) # Taking input from user ----------
for n in range(num+1):
if(n>1):
break
else:
print(n)
In [ ]:
6. Write a python program for determining how many Armstrong numbers exist within a given range.
In [23]:
import math #Import the math module --------
sum=0
while(n1>0):
temp=n1%10
sum=sum+math.pow(temp,size)
n1=n1//10
if sum==n:
else:
n1=int(input("Enter the starting range: ")) # Taking input from user --------
n2=int(input("Enter the ending range: ")) # Taking input from user --------
for i in range(n1,n2+1):
if(arm(i)):
print(i)
153
370
371
407
In [ ]:
7. Write a Program in python to find the sum of all the Prime numbers between a given ranges
of numbers.
In [1]:
def prime(n): # define prime functio for n ------------------
count=0
for i in range(2,n):
if(n%i==0):
count=1
if(count==1):
return False
else:
return True
def Prime_sum(): # define sum function for printing the sum of prime numbers--------
sum=0
for i in range(n1+1,n2+1):
if(prime(i)):
sum=sum+i
return sum
n1=int(input("Enter the starting range: ")) # Taking inputs from the user ---------
n2=int(input("Enter the ending range: ")) # Taking inputs from the user ---------
for i in range(n1,n2+1):
if(i==1):
continue;
elif(prime(i)):
print(i)
print("sum = ",Prime_sum())
11
13
17
19
sum = 60
In [ ]:
8. Given a maximum of four digit to the base 17(10 -> A, 11 -> B, 12 -> C, 16 -> G) as input, output its decimal value.
In [27]:
while(True):
hexn=input("Enter a 4 digit base 17 number where G stands for 16: ").upper() # Taking input from user -----------
lhexn=len(hexn)
if(lhexn<=4):
break
num=0
for i in range(lhexn):
ch=hexn[i]
n=hstr.index(ch)
num=17*num+n
print(num)
10980
In [ ]: