有一个机器人想要去充电点给自己充电。 机器人从原始点(0,0)在二维平面上移动。机器人可以按照给定的步骤向上,下,左和右移动。 机器人运动的轨迹如下图所示:
$client = new \Google_Client();
$client->setAuthConfig("/pathformyclient file/client.json");
$client->addScope(\Google_Service_CloudTalentSolution::JOBS);
$client->setHttpClient(new \GuzzleHttp\Client(['verify' => false]));
$cloudTalentSolutionClient = new \Google_Service_CloudTalentSolution($client);
$projectId = "my project ID";
$parent = sprintf('projects/%s', $projectId);
$company = new \Google_Service_CloudTalentSolution_Company();
$company->setName("company name");
$company->setDisplayName("company name");
$company->setExternalId("1");
$ci = new \Google_Service_CloudTalentSolution_CreateCompanyRequest();
$ci->setCompany($company);
$com = $cloudTalentSolutionClient->projects_companies->create($projectId,ci,array('parent' => $parent));
dump($com);die
然后,程序的输出应为: 2
我的代码是
UP 5
DOWN 3
LEFT 3
RIGHT 2
我收到一个错误ValueError:没有足够的值要解压(预期2,得到1)
答案 0 :(得分:0)
import math
pos=[0,0]
moves={"UP":[0,1],
"DOWN":[0,-1],
"LEFT":[-1,0],
"RIGHT":[1,0]}
data = list()
num = int(input())
for i in range(int(num)):
n = input()
data.append(n)
for inp in data:
parts=inp.split()
mv=parts[0]
val=parts[1]
if mv in moves and val.isnumeric():
pos[0] += moves[mv][0]*int(val)
pos[1] += moves[mv][1]*int(val)
distance=math.sqrt(pos[0]**2 + pos[1]**2)
print(round(distance))
答案 1 :(得分:0)
pos = {
"x": 0,
"y": 0
}
z=int(input())
c=0
while (c!=z):
n = input()
c=c+1
if not n:
break
direction,steps=n.split()
if direction == "UP":
pos["y"] += int(steps)
elif direction == "DOWN":
pos["y"] -= int(steps)
elif direction == "LEFT":
pos["x"] -= int(steps)
elif direction == "RIGHT":
pos["x"] += int(steps)
print (int(round((pos["x"]**2 + pos["y"]**2)**0.5)))
答案 2 :(得分:0)
import math
x=int(input())
dict1={"UP":0,"DOWN":0,"LEFT":0,"RIGHT":0}
for i in range(x):
y=input().split()
dict1[y[0].upper()]=int(y[1])
#print(dict1)
dist=math.sqrt((dict1["UP"]-dict1["DOWN"])**2 + (dict1["LEFT] - dict1["RIGHT"])**2)
dist=int(round(dist))
print(dist)
答案 3 :(得分:0)
dict= {"x":0, "y":0}
while True:
a = input("enter your direction for the robot(UP, DOWN)etc: ")
if a=="UP":
dict["y"]+=5
elif a=="DOWN":
dict["y"]-=3
elif a=="LEFT":
dict["x"]-=3
elif a=="RIGHT":
dict["x"]+=2
elif a=="DIST":
d=math.sqrt(dict["x"]**2 + dict["y"]**2)
print(d)
break
else:
print("invalid entry, try again")