-3

I'm trying to break out of the def Converter loop and then onto my next code. I have tried return but it doesn't work. Break gives me a syntax error. Please edit the code directly since i'm really bad at imputing foreign code. This is python 3. Many Thanks

from turtle import Screen, Turtle

print("Please select your conversion:")

invalid_input = True
def Converter() :
  conversion = input ("metric to metric type mm, metric to imperial type mi, units of water type w, for physics equations type p, for math equations type m and for quick facts type q:")
  print("Please select your conversion:")

  if conversion == "mm":
    #selection = "metric to metric conversions!"
    invalid_input = False
  elif conversion == "mi":
    selection = "metric to imperial conversions!"
    invalid_input = False
  elif conversion == "w":
    selection = "water conversions!"
    invalid_input = False
  elif conversion == "p":
    selection = "physics equations!"
    invalid_input = False
  elif conversion == "m":
    selection = "maths equations!"
    invalid_input = False
    print("You have selected", selection + "!")
  elif conversion == "q":
    selection = "quick facts!"
    invalid_input = False
  else:
    print("\n")
    print("Invalid! Please try again.\n \n \n")
while invalid_input : 
  Converter()

print("\n")
print("You have selected", selection + "!")

invalid_input = True
def start() :
  decision = input ("Is this correct? If correct type y, if incorrect type n.")
  if decision == "y":
        #stuff
        invalid_input = False
while invalid_input : True# this will loop until invalid_input is set to be True
start()
Nour Alaas
  • 11
  • 6
  • I don't think the duplicate is the right answer. What we have here is a scoping problem. The `invalid_input` in the function `Converter` isn't the same as the `invalid_input` on module level. – Matthias Nov 26 '18 at 14:10
  • @Matthias how can i fix it – Nour Alaas Nov 26 '18 at 15:32
  • Last statement in `Converter`: `return invalid_input`. Then call the function with `invalid_input = Converter()` in your `while` loop. – Matthias Nov 26 '18 at 16:26

1 Answers1

0

You have two while loops invalid_input which both marks to True.

Aliasgher Nooruddin
  • 534
  • 1
  • 6
  • 18