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 7577741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:15:57+00:00 2026-05-30T17:15:57+00:00

I am teaching myself Python and am running into a strange problem. What I

  • 0

I am teaching myself Python and am running into a strange problem. What I am trying to do is pass a list to a function, and have the function return a list where elements are the sum of the numbers around it, but what I thought would work produced some strange results, so I made a debug version of the code that still exhibts the behavior, which is as follows:

When I make an integer array, and pass it to an function which then uses a for loop print the individual values of the list, the numbers following the first one in each int are truncated.

For example, the following input and output:

Please enter a number: 101
Please enter a number: 202
Please enter a number: 303
Please enter a number: .
1
2
3

This happens no matter the input, if its 10, 101, or 13453 – the same behavior happens.

I know I am probably missing something simple, but for the sake of me, no amount of googling yields me a solution to this issue. Attached below is the code I am using to execute this. It is interesting to note: when printing the entire list outside of the for loop at any point, it returns the full and proper list (ie [‘101’, ‘202’, ‘303’])

Thanks!

temp = list()

def sum(list):
    print list
    for i in range(1, len(list)+1):
        print i
    return temp

L = list()
while True:
    input = raw_input("Please enter a number: ");
    if input.strip() == ".":
        break
    L.append(input);

print L

L2 = sum(L)
print L2
  • 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-05-30T17:15:58+00:00Added an answer on May 30, 2026 at 5:15 pm

    The loop

    for i in range(1, len(my_list)+1):
        print i
    

    iterates over the numbers from 1 to len(my_list), not over the items of the list. To do the latter, use

    for x in my_list:
        print x
    

    (I’ve renamed list to my_list to save you another headache.)

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

Sidebar

Related Questions

I am teaching myself some Python and I have come across a problem which
I'm teaching myself Python and I was translating some sample code into this class
Teaching myself some c# and my problem is that I have a class which
I am self teaching myself some python OOP, and I have created a simple
I'm teaching myself Python and I see the following in Dive into Python section
I have been teaching myself OpenGL programming using the Python wrapper PyOpenGL, and am
I'm teaching myself Python and my most recent lesson was that Python is not
So I'm teaching myself Python, and I'm having an issue with lists. I want
I was recently teaching myself Python and discovered the LBYL/EAFP idioms with regards to
I am teaching myself python. I was thinking of small programs, and came up

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.