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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:47:20+00:00 2026-06-02T11:47:20+00:00

I am writing some code to gain practice programming Python. The code is as

  • 0

I am writing some code to gain practice programming Python. The code is as follows:

#! /usr/bin/python

string ='''
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450'''.replace('\n','')

sum1 = 1
lis = [0,1,2,3,4]
lis2 = list()
while(1):
    for j in range(5):
        sum1 *= int(string[ lis[j] ])
    lis2.append(sum1)
    sum1 = 1
    for k in range(5):
        lis[k] = lis[k] + 1
    if lis[4] == 999:
        break
lis2.sort() 
print lis2

The program is used to find the greatest product of five consecutive digits in the 1000-digit number.

But the program didn’t work! An error

ValueError: invalid literal for int() with base 10:

occured when I ran the program!

I am a newbie to python!

  • 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-02T11:47:23+00:00Added an answer on June 2, 2026 at 11:47 am

    Your problem is simple: Python triple-quote strings include the line ending. There is a “newline” character at the end of each line, and int() is not happy.

    Easiest solution is to use the string .replace() method to remove the non-wanted newline characters. We use "\n" for a newline:

    string = """
    012345
    242432
    234323""".replace('\n', '')
    

    After I make that change, your program still doesn’t work, but that particular problem is gone.

    EDIT:
    To improve your program, I suggest you read up on “slicing” of strings in Python. You can use slicing to grab 5 characters at a time from the input string. Also, Python can loop over a string with an ordinary for loop, so you can get a 5-character slice and loop over it to multiply the five digits together.

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

Sidebar

Related Questions

I'm writing some code (just for fun so far) in Python that will store
I'm writing some code to parse a string into a double, but this string
I am writing some code in Python something like this: import sys try: for
So I was writing some code today that basically looks like this: string returnString
I'm writing some code in python and I'm having trouble when trying to retrieve
I'm writing some code for web development using Google Python Appengine. In my code
I'm writing some code that has a lot of substitution. There's a list<char> productions
I am writing some code to type strings using the Robot class. Everything is
I am writing some code that connects to a website, and using C#, and
i am writing some code in vb.net that will be generating a pdf file.

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.