Jump to content
cp/m

[help][py] debugging

Recommended Posts

Am nevoie de ajutor pentru a gasi bug-ul in programul asta:


import sys
var={}
com=""
i=0
j=0
comm=[]
co=""
print "##########Source##########"
while co!="HALT":
co=raw_input()
comm.append(co)
i=i+1
print "##########Execution##########"
while j<i:
com=comm[j]
if com[0:4]=="READ":
var[com[6:7]]=input()
if com[0:5]=="TELLN":
if var.has_key(com[7:8]):
print var[com[7:8]]
elif com[0:4]=="TELL":
if var.has_key(com[6:7]):
print var[com[6:7]],
if com[0:4]=="MAKE":
var[com[5:6]]=0
if com[1:2]=="=":
var[com[0:1]]=eval(com[2:len(com)])
if com[0:4]=="MOVE":
if var.has_key(com[5:6]) and var.has_key(com[7:8]):
var[com[5:6]]=var[com[7:8]]
if com[0:3]=="PUT":
if var.has_key(com[4:5]):
var[com[4:5]]=com[6:7]
j=j+1

Incercati urmatorul program:


e=12+3/2
TELLN e
HALT

Mie nu-mi merge. :S

Link to comment
Share on other sites

In primul rand vreau sa afirm ca e cel mai urat cod care l-am vazut vreodata, in al doilea rand te intreb de ce ai importat sys :) ?

##########Source##########
e=12+3/2
TELLN e
HALT
##########Execution##########
13

Python | import sys var={} com="" i= - CmiN - 1jFmR9NT - Pastebin.com

Unde ti-am pus cate un diez am facut eu corectura, greseli erau la valorile ce delimitau substring-urile, indexii aia dintre paranteze aplicate pe siruri, erau prea mari.

Link to comment
Share on other sites

Daca te referi la goto nu ... nu exista din mai multe motive: python e un limbaj de un nivel foarte inalt, cred ca cel mai inalt nivel posibil :), iar instructiunea respectiva se foloseste mai mult in programarea low level, dar in python asa ceva ar fi foarte instabil si putin aiurea, de aceea poti folosi functiile.


def func():
....<bla bla>
while <ala bala>:
....func()
....<bla bla>
....if <ala bala>:
........func()

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...