Advertisement
bojjenclon

Pre-Calculus

Jan 3rd, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.74 KB | None | 0 0
  1. from math import pow, sqrt, cos, acos, radians, degrees
  2.  
  3. def SSS():
  4.     try:
  5.         a = input( "a = " )
  6.         b = input( "b = " )
  7.         c = input( "c = " )
  8.     except:
  9.         print( "Input must be numbers only.\n" )
  10.        
  11.         return
  12.  
  13.     try:
  14.         A = degrees( acos( ( pow( b, 2 ) + pow( c, 2 ) - pow( a, 2 ) ) / ( 2 * b * c ) ) )
  15.         B = degrees( acos( ( pow( a, 2 ) + pow( c, 2 ) - pow( b, 2 ) ) / ( 2 * a * c ) ) )
  16.         C = degrees( acos( ( pow( a, 2 ) + pow( b, 2 ) - pow( c, 2 ) ) / ( 2 * a * b ) ) )
  17.        
  18.         degreeSymbol = unichr( 176 )
  19.        
  20.         print( "\nA = %.1f%s\nB = %.1f%s\nC = %.1f%s\n" % ( A, degreeSymbol, B, degreeSymbol, C, degreeSymbol ) )
  21.     except Exception, e:
  22.         print( "\n%s\nPlease check your input and try again.\n" % ( e ) )
  23.  
  24. def SAS():
  25.     side = raw_input( "Side: " )
  26.    
  27.     if( side == "a" ):
  28.         try:
  29.             b = input( "b = " )
  30.             c = input( "c = " )
  31.             A = input( "A = " )
  32.         except:
  33.             print( "Input must be numbers only.\n" )
  34.            
  35.             return
  36.        
  37.         try:
  38.             a = sqrt( pow( b, 2 ) + pow( c, 2 ) - ( 2 * b * c * cos( radians( A ) ) ) )
  39.            
  40.             print( "\na = %.1f\n" % ( a ) )
  41.         except Exception, e:
  42.             print( "\n%s\nPlease check your input and try again.\n" % ( e ) )
  43.     elif( side == "b" ):
  44.         try:
  45.             a = input( "a = " )
  46.             c = input( "c = " )
  47.             B = input( "B = " )
  48.         except:
  49.             print( "Input must be numbers only.\n" )
  50.            
  51.             return
  52.        
  53.         try:
  54.             b = sqrt( pow( a, 2 ) + pow( c, 2 ) - ( 2 * a * c * cos( radians( B ) ) ) )
  55.            
  56.             print( "\nb = %.1f\n" % ( b ) )
  57.         except Exception, e:
  58.             print( "\n%s\nPlease check your input and try again.\n" % ( e ) )
  59.     elif( side == "c" ):
  60.         try:
  61.             a = input( "a = " )
  62.             b = input( "b = " )
  63.             C = input( "C = " )
  64.         except:
  65.             print( "Input must be numbers only.\n" )
  66.            
  67.             return
  68.            
  69.         try:
  70.             c = sqrt( pow( a, 2 ) + pow( b, 2 ) - ( 2 * a * b * cos( radians( C ) ) ) )
  71.            
  72.             print( "\nc = %.1f\n" % ( c ) )
  73.         except Exception, e:
  74.             print( "\n%s\nPlease check your input and try again.\n" % ( e ) )
  75.     else:
  76.         print( "Invalid input.\n" )
  77.  
  78. def heronArea():
  79.     try:
  80.         a = input( "a = " )
  81.         b = input( "b = " )
  82.         c = input( "c = " )
  83.     except:
  84.         print( "Input must be numbers only.\n" )
  85.        
  86.         return
  87.    
  88.     try:
  89.         s = ( a + b + c ) / 2.0
  90.        
  91.         area = sqrt( s * ( s - a ) * ( s - b ) * ( s - c ) )
  92.        
  93.         print( "\nArea = %.1f\n" % ( area ) )
  94.     except Exception, e:
  95.         print( "\n%s\nPlease check your input and try again.\n" % ( e ) )
  96.  
  97. def main():
  98.     while( True ):
  99.         try:
  100.             selection = input( "Selection:\n1 = SSS\n2 = SAS\n3 = Heron's Area Formula\nAnything Else = Exit\n" )
  101.            
  102.             if( selection == 1 ):
  103.                 SSS()
  104.             elif( selection == 2 ):
  105.                 SAS()
  106.             elif( selection == 3 ):
  107.                 heronArea()
  108.             else:
  109.                 break
  110.         except:
  111.             print( "\nExiting...\n" )
  112.            
  113.             break
  114.  
  115. if __name__ == '__main__':
  116.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement