Question: PYTHON: can someone help me with my code? Step 3: Creating a Bar Graph In this step you will create a bar graph using the
PYTHON: can someone help me with my code?
Step 3: Creating a Bar Graph
In this step you will create a bar graph using the return value from the seq3np1 function as the height of each bar. You will use the loop code that you wrote in the previous step, but in order to make this work, please pay attention to the directions specified below to avoid errors in your code. Where you write the code will make a difference.
At the top of your code file:
1. Setup your turtle and screen objects.
2. Define a function called draw_bar with the formal parameters myturtle and height . The function will draw one bar in a bar chart
a. Formal Parameters: myturtle - the turtle object that will draw each bar in the chart, height - the height of the bar in the chart
b. Repeat the following steps two times (use a for loop)
1. Move forward 10 units 2. Turn left 90 degrees 3. Move forward height units 4. Turn left 90 degrees
Before the for loop (that is already created at the bottom):
1. Move the turtle to the location (-200, 0) without drawing a line.
2. Set the speed to 0.
In the body of the for -loop (at the bottom):
1. Define a variable called bar_height and assign it the value returned from seq3np1 .The value returned from seq3np1 is the count, which is also the height of the bar.
2. Call draw_bar passing in the necessary values. The variable bar_height represents the height of each bar in the graph.
3. Move the turtle forward 10 units.
MY CODE:
def seq3np1(n): count = 0 while n != 1: count +=1 if n % 2 == 0: n = n // 2 else: n = n * 3 + 1 return count
def per(): for start in range (1,51): variable = seq3np1(start) print("The start value =", start," :the return value =", variable) per()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
