You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have complete part7-18 ,which is "own_programming_language"task, a very enthralling and challenging task, it takes me a few hours to accomplish it, and it seems running correctly cause all the answer it return are right( as same as that in the example),but when I run my code with TMC, it takes so much long time and can't return a result, just like:
just like this for a few hours, I can't solve it by my self and I have no idea about what's wrong, if you can help me with it, I'll be so much appreciate cause I will got all my task done 100%,all of them!
anyway, this is my code:
Write your solution here
import string
dic = {character: 0 for character in string.ascii_uppercase}
output=[]
newbegin=0
def run(order:list):
sign=1
while sign:
sign=itera(order,begin=newbegin)
return output
def itera(order:list,begin):
global newbegin
for i in range(begin,len(order)):
order_list=order[i].split(" ") #每一行命令的数组
act=order_list[0] #取出命令
if act in["MOV" ,"ADD","SUB" ,"MUL"]:
var=order_list[1]
val = int(dic[order_list[2]]) if order_list[2] in string.ascii_uppercase else int(order_list[2])
if act=="MOV": #MOV [variable] [value]
dic[var]=val
elif act=="ADD": #ADD [variable] [value]
dic[var]+=val
elif act=="SUB": #SUB [variable] [value]
dic[var]-=val
elif act=="MUL": #MUL [variable] [value]
dic[var]*=val
elif act=="IF": #IF [condition] JUMP [location]
com_1=order_list[1] # 前者
com1=int(dic[com_1]) # 前者值
express=order_list[2] #比较符号
com_2=order_list[3] #后者
com2 = int(dic[com_2]) if com_2 in string.ascii_uppercase else int(com_2)
if express=="==" and com1==com2:
act="JUMP"
elif express=="!=" and com1!=com2:
act="JUMP"
elif express=="<" and com1<com2:
act="JUMP"
elif express=="<=" and com1<=com2:
act="JUMP"
elif express==">" and com1>com2:
act="JUMP"
elif express==">=" and com1>=com2:
act="JUMP"
else: #条件不满足,下一条命令
pass
elif act=="PRINT": #PRINT [value]
va=order_list[1]
pva = dic[va] if va in string.ascii_uppercase else int(va)
output.append(pva)
elif act=="END":
return 0
else:
pass
if act=="JUMP": #JUMP [location]
index=order_list.index("JUMP") #定位
loca=order_list[index+1]+":" #取出跳的位置
for k in range(len(order)):
if order[k] == loca:
global newbegin
newbegin=k+1 #定义重新循环的位置
return 1
break
if i==len(order)-1: #不是END的最后一行,且没有跳出循环:
return 0
The text was updated successfully, but these errors were encountered:
I have complete part7-18 ,which is "own_programming_language"task, a very enthralling and challenging task, it takes me a few hours to accomplish it, and it seems running correctly cause all the answer it return are right( as same as that in the example),but when I run my code with TMC, it takes so much long time and can't return a result, just like:
just like this for a few hours, I can't solve it by my self and I have no idea about what's wrong, if you can help me with it, I'll be so much appreciate cause I will got all my task done 100%,all of them!
anyway, this is my code:
Write your solution here
import string
dic = {character: 0 for character in string.ascii_uppercase}
output=[]
newbegin=0
def run(order:list):
sign=1
while sign:
sign=itera(order,begin=newbegin)
return output
def itera(order:list,begin):
global newbegin
for i in range(begin,len(order)):
order_list=order[i].split(" ") #每一行命令的数组
act=order_list[0] #取出命令
The text was updated successfully, but these errors were encountered: