Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import pow, sqrt, cos, acos, radians, degrees
- def SSS():
- try:
- a = input( "a = " )
- b = input( "b = " )
- c = input( "c = " )
- except:
- print( "Input must be numbers only.\n" )
- return
- try:
- A = degrees( acos( ( pow( b, 2 ) + pow( c, 2 ) - pow( a, 2 ) ) / ( 2 * b * c ) ) )
- B = degrees( acos( ( pow( a, 2 ) + pow( c, 2 ) - pow( b, 2 ) ) / ( 2 * a * c ) ) )
- C = degrees( acos( ( pow( a, 2 ) + pow( b, 2 ) - pow( c, 2 ) ) / ( 2 * a * b ) ) )
- degreeSymbol = unichr( 176 )
- print( "\nA = %.1f%s\nB = %.1f%s\nC = %.1f%s\n" % ( A, degreeSymbol, B, degreeSymbol, C, degreeSymbol ) )
- except Exception, e:
- print( "\n%s\nPlease check your input and try again.\n" % ( e ) )
- def SAS():
- side = raw_input( "Side: " )
- if( side == "a" ):
- try:
- b = input( "b = " )
- c = input( "c = " )
- A = input( "A = " )
- except:
- print( "Input must be numbers only.\n" )
- return
- try:
- a = sqrt( pow( b, 2 ) + pow( c, 2 ) - ( 2 * b * c * cos( radians( A ) ) ) )
- print( "\na = %.1f\n" % ( a ) )
- except Exception, e:
- print( "\n%s\nPlease check your input and try again.\n" % ( e ) )
- elif( side == "b" ):
- try:
- a = input( "a = " )
- c = input( "c = " )
- B = input( "B = " )
- except:
- print( "Input must be numbers only.\n" )
- return
- try:
- b = sqrt( pow( a, 2 ) + pow( c, 2 ) - ( 2 * a * c * cos( radians( B ) ) ) )
- print( "\nb = %.1f\n" % ( b ) )
- except Exception, e:
- print( "\n%s\nPlease check your input and try again.\n" % ( e ) )
- elif( side == "c" ):
- try:
- a = input( "a = " )
- b = input( "b = " )
- C = input( "C = " )
- except:
- print( "Input must be numbers only.\n" )
- return
- try:
- c = sqrt( pow( a, 2 ) + pow( b, 2 ) - ( 2 * a * b * cos( radians( C ) ) ) )
- print( "\nc = %.1f\n" % ( c ) )
- except Exception, e:
- print( "\n%s\nPlease check your input and try again.\n" % ( e ) )
- else:
- print( "Invalid input.\n" )
- def heronArea():
- try:
- a = input( "a = " )
- b = input( "b = " )
- c = input( "c = " )
- except:
- print( "Input must be numbers only.\n" )
- return
- try:
- s = ( a + b + c ) / 2.0
- area = sqrt( s * ( s - a ) * ( s - b ) * ( s - c ) )
- print( "\nArea = %.1f\n" % ( area ) )
- except Exception, e:
- print( "\n%s\nPlease check your input and try again.\n" % ( e ) )
- def main():
- while( True ):
- try:
- selection = input( "Selection:\n1 = SSS\n2 = SAS\n3 = Heron's Area Formula\nAnything Else = Exit\n" )
- if( selection == 1 ):
- SSS()
- elif( selection == 2 ):
- SAS()
- elif( selection == 3 ):
- heronArea()
- else:
- break
- except:
- print( "\nExiting...\n" )
- break
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement