• 判断10步能不能回到原点


    题目描述:

    # You live in the city of Cartesia where all roads are laid out in a perfect grid.
    # You arrived ten minutes too early to an appointment, so you decided
    # to take the opportunity to go for a short walk. The city provides
    # its citizens with a Walk Generating App on their phones --
    # everytime you press the button it sends you an array of
    # one-letter strings representing directions to walk
    # (eg. ['n', 's', 'w', 'e']). You always walk only a single block in a direction
    # and you know it takes you one minute to traverse one city block,
    # so create a function that will return true if the walk the app gives you will
    # take you exactly ten minutes (you don't want to be early or late!) and will, of course,
    # return you to your starting point. Return false otherwise.

    我的解答:
    def is_valid_walk(walk):
    if len(walk) != 10:
    return False
    if walk.count('n') == walk.count('s'):
    if walk.count('w') == walk.count('e'):
    return True
    return False



  • 相关阅读:
    Beta冲刺——集合随笔
    Beta冲刺——用户调查报告
    Beta冲刺——总结
    Beta冲刺——代码规范、冲刺任务与计划
    Beta冲刺——Day 7
    Beta冲刺——Day 6
    Beta冲刺——Day 5
    Beta冲刺——Day 4
    Beta冲刺——Day3
    beta冲刺汇总
  • 原文地址:https://www.cnblogs.com/wlj-axia/p/12639831.html
Copyright © 2020-2023  润新知