Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


+4 votes

My output is currently: "2 4 8 16"

I need to start at 1, so it reads "1 2 4 8 16." When i change my range or accumulator, i just get the number of 0's that i wanted to count up.

How can i make it so i can start with 1 and still count up?

asked in CSC201 Spring 2021 by (8 points)
reopened by

4 Answers

+3 votes

Think of 2^? generates 1. i.e. don't start with i = 1.

answered by (337 points)
+3 votes

when you write the for loop have it start at 0 so when you do 2 to the power of 'i' or any varibale you used in the for loop, it starts at 1.

answered by (132 points)
+2 votes

You can try range(number + 1). You have to start from 0 because 2^0 is 1. So no matter what number you enter, the first number returned is always 1

answered by (8 points)
+2 votes

Hi Janine!
You will want to set your initial variable to 0 because anything to the power of 0 is 1. Then you will want to accumulate that variable by 1 so each time through the loop the number is raised to the next power.

answered by (8 points)