Skip to content

Question 15 solutions not producing the correct output #142

Description

@hudnutt

Describe the bug
Question 15 solutions not producing the correct output (except for the Python 2 solution which is correct)

To Reproduce
Paste the solutions in your editor of choice and run the code

Expected behavior
For input '9' I expected a result of 11106

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):
n/a

Smartphone (please complete the following information):
n/a

Additional context

The Python 2 solution is correct

The first Python 3 solution does not run and returns error:
tmp+=a # concatenating 'a' to 'tmp'
TypeError: can only concatenate str (not "int") to str

The second Python 3 solution returns 90 instead of 11106

The solution by ChichiLovesDonkeys does not have a print statement. Even with that it outputs 90 instead of 11106.

The solution by lcastrooliveira returns 90 instead of 11106

The solution by apenam7 returns 90 instead of 11106

I think in all these instances not casting the user input digit to a string is the source of the problem. The solution I devised gives the correct answer of 11106.

a = input("Enter a digit ")
print(sum([int(str(a) * i) for i in range(1,5)]))

Activity

  1. darkprinx commented on Jul 23, 2026

    @darkprinx
    Owner

    Verified all 5 Q15 solutions against input 9 (expected 11106) — turns out 4 of them already compute the correct answer (must have been fixed since this was filed). The only real remaining bug was ChichiLovesDonkeys' solution silently computing the right answer without a print() call. Fixed in 35a3bce. Thanks for the detailed repro!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions