Lesson 17: Bar charts with Turtle and exponential growth

posted Mar 12, 2020, 8:04 AM by Attila Lengyel
import random as r

#series = [0,0,0,0,0,0]
#for x in range(10000):
# dice = r.randint(1,6)
# series[dice-1] = series[dice-1] + 1

series = [1]
for x in range(14):
growth= series[len(series)-1]
growth= growth* 2;
series.append(growth)

import turtle as t
st = t.Turtle()

st.penup()
st.setposition(-200,-200)
st.pendown()
st.fd(400)
st.penup()
st.setposition(-200,-200)
st.pendown()
st.left(90)
st.fd(400)

x = -230
for s in series:
x = x + 40
st.penup()
st.setposition(x,-200)
st.pendown()
height = (400 * s) / max(series)
st.begin_fill()
st.fd(height)
st.write(s)
st.right(90)
st.fd(20)
st.right(90)
st.fd(height)
st.end_fill()
st.right(180)



Comments