题解 | #坐标移动#

坐标移动

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

receive = input().split(";")
x,y=0,0
for i in receive:
    if 1<len(i)<=3:
        condition=i[1:]
        if condition.isdigit():
            if i[0]=='A':
               x-=1*int(condition) 
            if i[0]=='D': 
               x+=1*int(condition) 
            if i[0]=='S': 
                y-=1*int(condition) 
            if i[0]=='W': 
                y+=1*int(condition) 
print(str(x)+','+str(y))

Python isdigit() 方法检测字符串是否只由数字组成,只对 0 和 正数有效。

str.isdigit()

如果字符串只包含数字则返回 True 否则返回 False。

全部评论

相关推荐

在看数据的傻狍子很忙碌:学生思维好重,而心很急,自己想想真的能直接做有难度的东西吗?任何错误都是需要人担责的,你实习生可以跑路,你的同事领导呢
点赞 评论 收藏
分享
05-09 13:22
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务