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

  • Home
  • SEARCH
  • 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 8326597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:48:50+00:00 2026-06-09T00:48:50+00:00

How can I convert this while-loop into a function, so I can call it

  • 0

How can I convert this while-loop into a function, so I can call it multiple times.

i = 0
numbers = []
while i < 6:
    print "At the top of i is %d" % i
    numbers.append(i)


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

print "The numbers: "

for num in numbers:
    print num
  • 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-09T00:48:52+00:00Added an answer on June 9, 2026 at 12:48 am
    def fun_name():
        i = 0
        numbers = []
        while i < 6:
            print "At the top of i is %d" % i
            numbers.append(i)
            i = i + 1
        print "Numbers now: ", numbers
        print "At the bottom i is %d" % i
    
        print "The numbers: "
    
        for num in numbers:
            print num
    

    you can add, remove part of code you need. You can also return some value to use in main program.

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

Sidebar

Related Questions

Can I convert this into 1 command line on bash in sqlplus? cause i
how can i convert this into an array? if someone searches for lo he
is there anyway that I can convert this to use RSA encryption? im kinda
Can anyone convert this curl command that works in command line to php code
How can I convert this to preg_match? $urlregex = (https?|ftp)://([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&;%$-]+)*@)*((?:(25[0-5]|2[0-4]\d|[01]\d{2}|[1-9]\d|[1-9])\.){3}(25[0-5]|2[0-4]\d|[01]\d{2}|[1-9]\d|[1-9]|0)|localhost|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:\d+)*(($|[a-zA-Z0-9.,?'+\\&;%\$#=~_-]+))*; if (!eregi($urlregex, $_POST['url'])) {
How can i convert this JSON array: This is a serialized JSON array 2012-06-18
How can I convert this type of Arraylist to Two Dimensional Arraylist ? ArrayList<ArrayList<String>>
How can i convert this $langClarContent = > &# 1059.,&#1095.,&#1080.,&# 1090.,&# 1077.,&# 1083.,Dokeos &#
How can I convert this document: <Root> <!-- yes, I know I don't need
Does any on know how can I convert this $events = array( array(type =>

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.