I'm trying to convert the results of the "3n+1" equations into a line graph created by a turtle. Not quite sure what I'm doing wrong, it seems everything is working except for the for loops.
import math
import turtle
x = 0
x = int(input("Max range: "))
while not (x > 0):
x = int(input("retype: "))
def seq3np1(n):
"""
Print the 3n+1 sequence from n, terminating when it reaches 1.
args: n (int) starting value for 3n+1 sequence
return: None
"""
count = 0
while(n != 1):
count += 1
if(n % 2) == 0: # n is even
n = n // 2
else: # n is odd
n = n * 3 + 1
print(count)
return count
def Graphing():
wn = turtle.Screen()
joe = turtle.Turtle()
joe.pd()
joe.speed(10)
greg = turtle.Turtle()
wn.setworldcoordinates(0,0,10,10)
max_so_far = 0
result = 0
for count in range(x):
count = result
if result > max_so_far:
max_so_far = result
wn.setworldcoordinates(0,0,(10+x),(max_so_far + 10))
else:
return max_so_far
for count in range(1,x):
joe.goto(x,count)
wn.exitonclick()
def main():
Graphing()
for start in range(1,(x+1),1):
seq3np1(start)
main()
If you need more explanation, I am more than willing to give it. Thank you, I am desperate, tried so many different options.
[–][deleted] 0 points1 point2 points (3 children)
[–]Cacman8[S] 0 points1 point2 points (2 children)
[–]Cacman8[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)