#Sum of numbers from 1 to 100
sum = 0
for n in range(1,101):
sum = sum + n
print "Sum = ", sum
Result:
Sum = 5050
#Area of a Triangle by Heron's formula
import math
a, b, theta = input('Enter a, b & angle in degree: \n')
theta = math.pi*theta/180 #Convert into radian
c = math.sqrt(a*a + b*b - 2*a*b*math.cos(theta))
s =(a + b + c)*0.5
area = math.sqrt(s*(s - a)*(s - b)*(s - c))
print 'Area = ', area
sum = 0
for n in range(1,101):
sum = sum + n
print "Sum = ", sum
Result:
Sum = 5050
#Area of a Triangle by Heron's formula
import math
a, b, theta = input('Enter a, b & angle in degree: \n')
theta = math.pi*theta/180 #Convert into radian
c = math.sqrt(a*a + b*b - 2*a*b*math.cos(theta))
s =(a + b + c)*0.5
area = math.sqrt(s*(s - a)*(s - b)*(s - c))
print 'Area = ', area
No comments:
Post a Comment
Thanks for comment.