Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question 15 solutions not producing the correct output #142

Open
hudnutt opened this issue Jun 19, 2023 · 0 comments
Open

Question 15 solutions not producing the correct output #142

hudnutt opened this issue Jun 19, 2023 · 0 comments

Comments

@hudnutt
Copy link

hudnutt commented Jun 19, 2023

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)]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant