题解 | 坐标移动

坐标移动

https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29

input = input().split(';')

x , y = 0, 0
for cmd in input:
    if len(cmd)>=2 and cmd[1:].isdigit():
        step = int(cmd[1:])
        direct = cmd[0].upper()
        if 0<step<100:
            if direct=='W':
                y+=step
            if direct=='A':
                x-=step
            if direct=='S':
                y-=step
            if direct=='D':
                x+=step

print(x,',',y,sep='')#print()的参数
r'''
objects - 复数,表示可以一次输出多个对象。输出多个对象时,需要用 , 分隔。
sep - 用来间隔多个对象,默认值是一个空格。
end - 用来设定以什么结尾。默认值是换行符 \n,我们可以换成其他字符串。
file - 要写入的文件对象。
'''

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务