Advertisement
Bishwajit123

Untitled

Feb 17th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.52 KB | None | 0 0
  1. #-----------1-----------sum and average-------------------
  2. n = int(input('Enter how many number u input : '))
  3. total = 0
  4. for i in range(1,n+1):
  5.     num = input(f"input number : ")
  6.     total += int(num)
  7.  
  8. print(f'the total sum :{total}')  
  9. print(f'the total avarege : {total/n}')
  10.  
  11.  
  12. # ------------------using function--------------
  13. def sumx(x):
  14.     total = 0
  15.     for i in range(1,x+1):
  16.         num = float(input('enter value : '))
  17.         total += num
  18.     return total
  19.  
  20. n = int(input('Enter number of data set : '))
  21. sumx= sumx(n)
  22. print(f'the total sum  : {sumx} and the average : {sumx/n}')
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. # ----------2-------- sum for 1/n -----------------------
  30. n = int(input('enter the value of n : '))
  31.  
  32. total = 0
  33. for i in range(1,n+1):
  34.     total += 1.0/i
  35. print(f' the calculated sum : {total}')  
  36.  
  37.  
  38. # ----2----using function-------
  39. def sumx(x):
  40.     total = 0
  41.     for i in range(1,x+1):
  42.         total += 1.0/i
  43.     return total    
  44. n = int(input('enter the value of n : '))
  45. print(f'total : {sumx(n)}')
  46.  
  47.  
  48.  
  49.  
  50.  
  51. # ----------3------------triangle---------------------------
  52. a= int(input('Enter a : '))
  53. b= int(input('Enter b : '))
  54. c= int(input('Enter c : '))
  55.  
  56.  
  57. if(a+b<c or a+c<b):
  58.     print('invalid length . ')  
  59. else:
  60.     perimeter= a+b+c
  61.     s = perimeter/2
  62.     area = pow((s*(s-a)*(s-b)*(s-c)),0.5)
  63.     print(f'the tirangle perimeter : {perimeter}')
  64.     print(f'the triangle area : {area}')    
  65.  
  66.  
  67.  
  68.  
  69.  
  70. # ------------------------gamma--------------------------
  71. #------------gamma=h1/(h1-h2)---------
  72. n = int(input('How many data set want to input : '))
  73.  
  74. sumh1 = 0
  75. sumh2 = 0
  76. for i in range(1,n+1):
  77.     h1= float(input('Enter the values of h1 : '))
  78.     sumh1 += h1    
  79. print('\n')
  80.  
  81. for i in range(1,n+1):
  82.     h2= float(input('Enter the values of h2 : '))    
  83.     sumh2 += h2
  84. avgh1 = sumh1/n
  85. avgh2 = sumh2/n
  86.  
  87. print(f'the calculated gamma {avgh1/(avgh1-avgh2)}')
  88.  
  89.  
  90. #-------------------------using function---------------------
  91. def sumx(x):
  92.     sumx = 0
  93.     for i in range(1,x+1):
  94.         h = float(input('Enter the value : '))
  95.         sumx += h
  96.     return sumx
  97.  
  98. n = int(input('How many data set want to input : '))    
  99. avgh1 = sumx(n)/n
  100. print('\n')
  101. avgh2 = sumx(n)/n
  102. print(f'the calculated gamma is : {avgh1/(avgh1-avgh2)}')
  103.  
  104.  
  105.  
  106.  
  107. # # ----------------------standard diviation= sqrt(x - average_x)/n)------------
  108. n = int(input('Enter number of data set : '))
  109.  
  110. sumx= 0
  111. for i in range(1,n+1):
  112.     x = float(input('Enter value of x : '))
  113.     sumx += x
  114. avgx = sumx/n
  115.  
  116. ssd = 0
  117. for i in range(1,n+1):
  118.     ssd += (x - avgx)**2
  119. std = (ssd/n)**0.5
  120.  
  121. print(f'The calculated standard diviation is : {std}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement