题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
s = input().split(";") x = y = 0 for i in s: if not i: continue try: num = int(i[1:]) if i[0] == "A": x = x - num if i[0] == "S": y = y - num if i[0] == "W": y = y + num if i[0] == "D": x = x + num except: continue print(f"{x},{y}")呜呜呜,大佬直接用try-except处理掉了所有异常。不满足条件的抛出异常后,全部不做处理,继续下一步。#字节跳动数据分析师面经#
OD专栏练习梳理 文章被收录于专栏
OD专栏练习梳理