python - Passing in variables into functions -


this code uses trigonometry in order find missing sides on triangle. works using sohcahtoa find these sides. problem code when try run code gives me invalid syntax when call user defined function: "get_method". please can tell wrong code , how solve consistent problem occurs in programmes.

import math  def get_method(question, method):     print("lable right-angle triangle.")     question = input("what trying find? type 'h' hypotenuse, 'a' adjacent or 'o' opposite.").lower().strip()     method = ""     if question == "h":         opposite_verify = input("do have length of opposite?\n"                               "type 'yes' or 'no'").strip().lower()         if opposite_verify == "yes":             method = "sine"         elif opposite_verify == "no":             adjacent_verify = input("do have length of adjacent?\n"                               "type 'yes' or 'no'").strip().lower()             if adjacent_verify == "yes":                 method = "cosine"             else:                 print("there's no way solve this.")      elif question == "a":         hypotenuse_verify = input("do have length of hypotenuse?\n"                               "type 'yes' or 'no'").strip().lower()         if hypotenuse_verify == "yes":             method = "cosine"         elif hypotenuse_verify == "no":             opposite_verify = input("do have length of opposite?\n"                               "type 'yes' or 'no'").strip().lower()             if opposite_verify == "yes":                 method = "tan"             else:                 print("there's no way solve this.")      elif question == "o":         hypotenuse_verify = input("do have length of hypotenuse?\n"                               "type 'yes' or 'no'").strip().lower()         if hypotenuse_verify == "yes":             method = "sine"         elif hypotenuse_verify == "no":             adjacent_verify = input("do have length of adjacent?\n"                               "type 'yes' or 'no'").strip().lower()             if adjacent_verify == "yes":                 method = "tan"             else:                 print("there's no way solve this.")      return method, question  def main(question, method):     angle = float(input("what degrees of angle?"))     angle /= (math.pi / 180)     if method == "sine" , question == "h":         opposite = float(input("what length of opposite angle?"))         hypotenuse = opposite / (math.sin(angle))         print("the length of hypotenuse {}".format(hypotenuse))     elif method == "sine" , question == "o":         hypotenuse = float(input("what length of hypotenuse?"))         opposite = hypotenuse * (math.sin(angle))         print("the length of opposite {}".format(opposite))     elif method == "cosine" , question == "a":         hypotenuse = float(input("what length of hypotenuse?"))         ajacent = hypotenuse * (math.cos(angle))         print("the length of ajacent {}".format(ajacent))     elif method == "cosine" , question == "h":         ajacent = float(input("what length of ajacent?"))         hypotenuse = ajacent / (math.cos(angle))         print("the length of hypotenuse {}".format(hypotenuse))     elif method == "tan" , question == "o":         ajacent = float(input("what length of ajacent?"))         opposite = ajacent * (math.tan(angle))         print("the length of opposte {}".format(opposite))     elif method == "tan" , question == "a":         opposite = float(input("what length z"))   get_method(question, method) main(question, method) 

as can see have problem passing in variables functions. , yes know code inefficient, new coding cut me slack.

since get_method() seems problem, let's take @ it. first, passing in arguments ignored , reset, toss arguments function -- define , call no arguments.

i've added couple of helper functions get_method() code:

import sys  def str_input(prompt=none):     return input(prompt).lower().strip()  def boolean_input(prompt=none):     return input(prompt + "type 'yes' or 'no': ").lower().strip() == "yes"  def get_method():     print("label right-angle triangle.")      question = str_input("what trying find? type 'h' hypotenuse, 'a' adjacent or 'o' opposite: ")      method = ""      if question == "h":         opposite_verify = boolean_input("do have length of opposite?\n")          if opposite_verify:             method = "sine"         else:             adjacent_verify = boolean_input("do have length of adjacent?\n")              if adjacent_verify:                 method = "cosine"             else:                 sys.exit("there's no way solve this.")      elif question == "a":         hypotenuse_verify = boolean_input("do have length of hypotenuse?\n")          if hypotenuse_verify:             method = "cosine"         else:             opposite_verify = boolean_input("do have length of opposite?\n")              if opposite_verify:                 method = "tan"             else:                 sys.exit("there's no way solve this.")      elif question == "o":         hypotenuse_verify = boolean_input("do have length of hypotenuse?\n")          if hypotenuse_verify:             method = "sine"         else:             adjacent_verify = boolean_input("do have length of adjacent?\n")              if adjacent_verify:                 method = "tan"             else:                 sys.exit("there's no way solve this.")      return method, question 

now can call via:

method, question = get_method() 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -