-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
142 lines (104 loc) · 2.27 KB
/
model.py
File metadata and controls
142 lines (104 loc) · 2.27 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 16 14:12:33 2019
@author: gynjkm
"""
"""
Model:
# Make a y variable.
# Make a x variable.
# Change y and x based on random numbers.
# Make a second set of y and xs, and make these change randomly as well.
# Work out the distance between the two sets of y and xs.
"""
#importing packages
import random
import math
#Assinging variables x0 and y0
y0 = random.randint(0,99)
x0 = random.randint(0,99)
print("y0 is", y0)
print("x0 is", x0)
#Building an algorithm to randomise the value of y0 one step
if random.random() < 0.5:
y0 = y0 + 1
else:
y0 = y0 - 1
print("After our first step y0 is now", y0)
#Building an algorithm to randomise the value of x0 one step
if random.random() < 0.5:
x0 = x0 + 1
else:
x0 = x0 - 1
print("After our first step x0 is now", x0)
#And a few more steps...
if random.random() < 0.5:
y0 = y0 + 1
else:
y0 = y0 - 1
if random.random() < 0.5:
x0 = x0 + 1
else:
x0 = x0 - 1
if random.random() < 0.5:
y0 = y0 + 1
else:
y0 = y0 - 1
if random.random() < 0.5:
x0 = x0 + 1
else:
x0 = x0 - 1
if random.random() < 0.5:
y0 = y0 + 1
else:
y0 = y0 - 1
if random.random() < 0.5:
x0 = x0 + 1
else:
x0 = x0 - 1
print("Three steps later x0 is", x0)
print("Three steps later y0 is", y0)
#Introducing x1 and y1
y1 = random.randint(0,99)
x1 = random.randint(0,99)
print("y1 is", y1)
print("x1 is", x1)
if random.random() < 0.5:
y1 = y1 + 1
else:
y1 = y1 - 1
if random.random() < 0.5:
x1 = x1 + 1
else:
x1 = x1 - 1
print("After our first step x1 is now", x1)
print("After our first step y1 is now", y1)
if random.random() < 0.5:
y1 = y1 + 1
else:
y1 = y1 - 1
if random.random() < 0.5:
x1 = x1 + 1
else:
x1 = x1 - 1
if random.random() < 0.5:
y1 = y1 + 1
else:
y1 = y1 - 1
if random.random() < 0.5:
x1 = x1 + 1
else:
x1 = x1 - 1
if random.random() < 0.5:
y1 = y1 + 1
else:
y1 = y1 - 1
if random.random() < 0.5:
x1 = x1 + 1
else:
x1 = x1 - 1
print("Three steps later x1 is", x1)
print("Three steps later y1 is", y1)
#Working out the distance between x0,y0 and x1,y1
distance = math.sqrt( ((x1 - x0)**2) + ((y1-y0)**2))
print ("The distance between our two points is", distance, "units")