@Nathan2196/

X^2 With Graph

Python

Keeps on squaring a number and plots the amount of time it took

fork
loading
Files
  • main.py
  • graph.png
  • graph1.png
  • requirements.txt
main.py
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
143
144
145
146
147
148
149
#libraries
import time
import matplotlib.pyplot as plt

#global vars 
global a 
global b 
global c
global starttime
global endtime
global totaltime
global start 
global end
global xaxis
global yaxis
global elapsed
global count
global count2
global totaltimeavg
global length
global summ
global avgtime
global predictionwait
global predictionlist 
global predictionmultiplier
global prediction 
global first 
global second
global newinput 
global oldinput
global timetakenlist

#var def
a = 2
b = 0
c = 0
starttime = 0
endtime = 0
totaltime = 0
start = 0
end = 0
xaxis = [] #time taken, total time
yaxis = [] #elapsed time
elapsed = 0
count = 0
count2 = 0
totaltimeavg = []
length = 0
summ = 0
avgtime = 0
predictionwait = 0
predictionlist = []
predictionmultiplier = []
prediction = 0
predictionavg = 0
first = 0
second = 0
newinput = 0
oldinput = 0
timetakenlist = []

#elapsed time start 
start = time.time()

#make a prediction based on previous average change 
while(count < 2):	
	length = 0 
	summ = 0
	starttime = 0
	end = 0
	endtime = 0
	totaltime = 0
	starttime = time.time()
	avgtime = 0
	b = a * a
	c = c + 1
	
	#count === c
	# time taken == total time 
	# time elapsed == elapsed 
	# sum == summ 
	# avgtime == summ / len 
	#length == totaltimeavg 

	endtime = time.time()
	totaltime = (endtime - starttime)
	oldinput = newinput
	newinput = totaltime
	
	if(count < 1):
		timetakenlist.append(newinput)
	else:
		timetakenlist.append((newinput/oldinput))
	print('LIST', timetakenlist)

	totaltimeavg.append(totaltime)

	length = len(totaltimeavg)
	summ = sum(totaltimeavg)
	avgtime = int(summ / length)

	xaxis.append(totaltime)
	end = time.time()
	elapsed = (end - start)
		
	yaxis.append(elapsed)
	
	#prediction
	predictionlist.append(totaltime)

	#for testing purposes
	totaltime = [0.1, 0.2]		
	
	#prediction 
	#if(prediction < 3):
	#first = (totaltime[0])
	#second = (totaltime[1])
	#first = totaltime[0:1]
	#second = totaltime[1:2]
	#print(totaltime)
	#totaltime = [str(i) for i in totaltime]
	#predictionavg = str(totaltime)
	#predictionavg[1:len(predictionavg)-1]
	#print(predictionavg)
	#predictionavg = 
	#predictionmultiplier.append(predictionavg)
	#print(predictionmultiplier)

	print("___________________________________________________")
	print("I am predicting it will take:", avgtime, "seconds")
	print("")
	print("number count:", c)
	print("time taken:", totaltime)
	print("elapsed time:", elapsed)
		
	#time.sleep(.01)

	a = b
	count = count + 1
	count2 = count2 + 1
	prediction += 1
	
	
	#count2 = count2 + 1

plt.plot(yaxis)
plt.savefig('graph1.png')
plt.show()