-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython 10.py
More file actions
64 lines (37 loc) · 1.13 KB
/
Copy pathpython 10.py
File metadata and controls
64 lines (37 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
20.Define a class with a generator which can iterate the numbers, which are divisible by 7, between a given range 0 and n.
# In[1]:
class number:
def __init__(self):
n=int(input('enter number'))
self.n=n
def show(self):
for i in range(0,(self.n)+1):
if (i%7==0):
yield(i)
num=number()
print(num.show())
for i in num.show():
print(i,end=',')
# In[ ]:
21.A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT
with a given steps. The trace of robot movement is shown as the following:
UP 5
DOWN 3
LEFT 3
RIGHT 2
The numbers after the direction are steps. Please write a program to compute the distance from current position after a
sequence of movement and original point. If the distance is a float, then just print the nearest integer.
# In[2]:
import math
UP=int(input('enter up'))
DOWN=int(input('enter down'))
LEFT=int(input('enter left'))
RIGHT=int(input('enter right'))
B=(UP-DOWN)
C=(LEFT-RIGHT)
D=math.sqrt(B**2+C**2)
print(round(D))
# In[ ]: