position - Python "Option" to determine IF ELSE decision is not working -



position - Python "Option" to determine IF ELSE decision is not working -

i'm trying write programme moving position. below here code.

def robot(): = input("please come in direction: ") j = input("please come in steps: ") k = int(j) #convert steps input integer x = 0 #x-axis position y = 0 #y-axis position xpos = "" ypos = "" alternative = 1 if (option == 1): if (i == "up"): y += k if (y > 0): steps = str(y) print ("i " + steps + " steps above") elif (y < 0): steps = str(y) print ("i " + steps + " steps below") alternative = input("1 go on moving, 0 terminate: ") elif (i == "down"): y -= k if (y < 0): steps = str(y) print ("i " + steps + " steps below") elif (y > 0): steps = str(y) print ("i " + steps + " steps above") alternative = input("1 go on moving, 0 terminate: ") elif (i == "left"): x -= k if (x < 0): steps = str(x) print ("i " + steps + " steps behind") elif (x > 0): steps = str(x) print ("i " + steps + " steps infront") alternative = input("1 go on moving, 0 terminate: ") elif (i == "right"): x += k if (x < 0): steps = str(x) print ("i " + steps + " steps behind") elif (x > 0): steps = str(x) print ("i " + steps + " steps infront") alternative = input("1 go on moving, 0 terminate: ") elif (option == 0): xpos = str(x) ypos = str(y) print ("i @ " + xpos + " on x-axis , " + ypos + " on y-axis") robot()

so output this, goes asking direction, , steps. after that, prints out how many steps in direction , prompts user either go on or stop.

so can see in code, added

option = input("1 go on moving, 0 terminate: ")

but if come in 1 option, doesn't bring me loop. can know or did wrong? in advance!

you missing loop, not checking condition termination/continue. rewritten code

i = input("please come in direction: ") j = input("please come in steps: ") k = int(j) #convert steps input integer x = 0 #x-axis position y = 0 #y-axis position xpos = "" ypos = "" alternative = 1 if (option == 1): if (i == "up"): y += k if (y > 0): steps = str(y) print ("i " + steps + " steps above") elif (y < 0): steps = str(y) print ("i " + steps + " steps below") alternative = input("1 go on moving, 0 terminate: ") if(option=="1"): homecoming 1 else: homecoming 0 elif (i == "down"): y -= k if (y < 0): steps = str(y) print ("i " + steps + " steps below") elif (y > 0): steps = str(y) print ("i " + steps + " steps above") alternative = input("1 go on moving, 0 terminate: ") if(option=="1"): homecoming 1 else: homecoming 0 elif (i == "left"): x -= k if (x < 0): steps = str(x) print ("i " + steps + " steps behind") elif (x > 0): steps = str(x) print ("i " + steps + " steps infront") alternative = input("1 go on moving, 0 terminate: ") if(option=="1"): homecoming 1 else: homecoming 0 elif (i == "right"): x += k if (x < 0): steps = str(x) print ("i " + steps + " steps behind") elif (x > 0): steps = str(x) print ("i " + steps + " steps infront") alternative = input("1 go on moving, 0 terminate: ") if(option=="1"): homecoming 1 else: homecoming 0 flag=1 while flag: flag=robot()

output:

>>> please come in direction: please come in steps: 1 1 steps above 1 go on moving, 0 terminate: 1 please come in direction: downwards please come in steps: 3 -3 steps below 1 go on moving, 0 terminate: 0 >>>

python position

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -