Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9135237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:47:53+00:00 2026-06-17T08:47:53+00:00

I have a very basic question about loops. I’m trying to get into programming

  • 0

I have a very basic question about loops. I’m trying to get into programming and am currently reading the book “Learn Python The Hard Way”, and got stuck on study drill number 5 on ex 33:
http://learnpythonthehardway.org/book/ex33.html

This is what my code looks like:

i = 0
numbers = []

def main(i, numbers):
    userloop = int(raw_input("Type in max value for the loop > "))
    while i < userloop:

        print "At the top i is %d" % i
        numbers.append(i)
        userincrease = int(raw_input("Increase > "))
        i += userincrease

        print "Numbers now: ", numbers
        print "At the bottom i is %d" % i


    print "The numbers: "
    print numbers
    for num in numbers:
    print num       


main(i, numbers)

The thing is that i want to use a for loop instead of the while loop. Is that even possible and then, how do I do it? I’ve tried simply exchanging

while i < userloop:

with

for i in range(userloop)

But then, the i value kinda resets every time it reaches the “top” of the loop.

Since I’m very much new to this, please don’t be too mean if i missed something obvious.

By the way, does anyone know whether this book is any good to begin with or am I wasting my time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:47:53+00:00Added an answer on June 17, 2026 at 8:47 am

    A for loop in python loops over a series of values provided by the expression after in. In Python we use the term iterable for anything that can produce such a series. That can be a range(), but it could be anything that can be iterated over (looped over). The loop variable i receives the next value on each iteration, whatever value there was before.

    Thus, the following is legal:

    for i in ('foo', 'bar', 'baz'):
        print i
        i = 'spam'
    

    but the i = 'spam' essentially does nothing.

    You’d have to approach it differently; skip those values instead:

    print_at = 0
    for i in range(userloop):
        if i >= print_at:
            print "At the top i is %d" % i
            numbers.append(i)
            userincrease = int(raw_input("Increase > "))
            print_at = i + userincrease
    
            print "Numbers now: ", numbers
            print "At the bottom i is %d" % i
    

    Every time you ask the user for an increase, we update the value print_at to be the sum of the current value of i plus that increase, and then proceed to ignore most of the loop body until i catches up with print_at.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic question about Ruby loops. This program as written returns
I'm a Ruby newbie. Have a very basic question about static and instance variables.
I have very basic question about Flex SDK, but I didn't find any resources
I have a very basic question about how to write to a plist. I
I have very basic question about the use of high performance cluster in our
I have a very basic question about the LDAP Protocol: Can a client be
I have a very basic question about MVC web applications in Java. Since the
I have a very basic question about binding between controls. I have a class
I have a very basic question about SVN. I know SVN has pretty strict
I have a very basic question about populating listviews in android. Right now, if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.