【Python Practice】Day 7- Question 20-21
2024-06-26 06:19:27 阅读次数:19
python,编程开发
'''
@Author: your name
@Date: 2020-07-12 21:20:43
@LastEditTime: 2020-07-12 22:36:06
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \vscode_py\day7.py
'''
# Question20:
# 生成一个类,里面包含一个迭代器,打印0~n中能被7整除的数
class Q20():
def by_seven(self, n):
for number in range(1,n + 1):
if number % 7 == 0: yield number
# Question21:
# 通过命令行输入机器人移动方向和位移,输出最终位置到原点的距离
import math
def Q21():
pose=[0,0]
while True:
dir=input().split()
if not dir:
break
if dir[0] == 'UP':
pose[1]+=int(dir[1])
elif dir[0] == 'DOWN':
pose[1]-=int(dir[1])
elif dir[0] == 'LEFT':
pose[0]-=int(dir[1])
elif dir[0] == 'RIGHT':
pose[0]+=int(dir[1])
else:
pass
distance=round(math.sqrt(pose[0]*pose[0]+pose[1]**2))
print(distance)
if __name__ == "__main__":
# divisible =Q20()
# generator=divisible.by_seven(int(input()))
# for number in generator:
# print(number)
Q21()
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/u_14355665/6099359,作者:Tech沉思录,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。
上一篇:【Python Practice】Day 4- Question 14-15
下一篇:【Windows 10 应用开发】跟随系统主题颜色