Question 15 solutions not producing the correct output
hudnutt opened this issue · 0 comments
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)]))