1
\$\begingroup\$
add9 = []

add9.append(int(input("Enter 1st 4-digit no.: ")))

print(f"The answer will be 2 and {str(add9[0])[0 :-1]} and {str(add9[0]-2)[-1]} = 2{add9[0]-2}")

add9.append(int(input("Enter 2nd 4-digit no.: ")))

add9.append(9999-add9[1]) 

print(f"The 3rd 4-digit is 9999 - {add9[1]}= {add9[2]}")

add9.append(int(input("Enter 4th 4-digit no.: ")))

add9.append(9999-add9[3]) 

print(f"The 5th 4-digit is 9999 - {add9[2]}= {add9[4]}")


print(f"""
So, 
{add9[0]}+{add9[1]} = {add9[0]+add9[1]}
{add9[0]+add9[1]}+{add9[2]} = {add9[0]+add9[1]+add9[2]}
{add9[0]+add9[1]+add9[2]}+{add9[3]} = {add9[0]+add9[1]+add9[2]+add9[3]}
{add9[0]+add9[1]+add9[2]+add9[3]}+{add9[4]} = {add9[0]+add9[1]+add9[2]+add9[3]+add9[4]}
""")

gives

Enter 1st 4-digit no.: 9999
The answer will be 2 and 999 and 7 = 29997
Enter 2nd 4-digit no.: 2345
The 3rd 4-digit is 9999 - 2345= 7654
Enter 4th 4-digit no.: 6789
The 5th 4-digit is 9999 - 7654= 3210

So,
9999+2345 = 12344
12344+7654 = 19998
19998+6789 = 26787
26787+3210 = 29997


[Program finished]

Code works fine. It's for kids to demo how to produce output using 3 inputs from user. The trick is to subtract 9999 from 2nd and 3rd input from user. I have tried to use as small syntax as possible.

Edit: 3rd and 5th digit are - 9999

Enter 1st 4-digit no.: 9990
The answer will be 2 and 999 and 8 = 29988
Enter 2nd 4-digit no.: 6667
The 3rd 4-digit is 9999 - 6667= 3332
Enter 4th 4-digit no.: 8888
The 5th 4-digit is 9999 - 3332= 1111

So,
9990+6667 = 16657
16657+3332 = 19989
19989+8888 = 28877
28877+1111 = 29988


[Program finished]

is working as expected

From calculator,

 Calculation 1  
(1/1) 9,990. +
(1/2) 6,667. =
(1/3) 16,657. +
(1/4) 3,332. =
(1/5) 19,989. +
(1/6) 8,888. =
(1/7) 28,877. +
(1/8) 1,111. =
(1/9) 29,988. 
\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$
  • To start, I wouldn't put everything in a list. There are benefits to putting all five numbers in a sequence, but that needn't happen until the end
  • You can expand your explanation for the "answer". First, it's unclear what you mean by "answer"; it's actually the fourth sum. Also, you can expand your explanation for each of the terms going into this fourth sum. Some of the notation I've shown is perhaps a little advanced for kids, so simplify it at your discretion.
  • You should be replacing your expressions at the bottom with a loop.
  • Where possible, you should be phrasing your operations as mathematical (mod, floor division) rather than string-based.
  • I think you have an algorithmic problem? When I enter 9990 for the first number, the predicted and actual fourth sum diverge.

Suggested

a = int(input("Enter 1st 4-digit no.: "))
sum4 = int(f'2{a//10}{(a - 2)%10}')
print(
    f"The fourth sum will be the concatenation of:"
    f"\n  2"
    f"\n  ⌊{a}/10⌋ = {a//10}"
    f"\n  mod({a} - 2, 10) = {(a - 2)%10}"
    f"\n= {sum4}"
    f"\n"
)

b = int(input("Enter 2nd 4-digit no.: "))
c = 9999 - b
print(f"The 3rd 4-digit no. is 9999 - {b} = {c}")

d = int(input("Enter 4th 4-digit no.: "))
e = 9999 - d
print(f"The 5th 4-digit no. is 9999 - {c} = {e}")

nums = (a, b, c, d, e)
print('\nSo,')
for i in range(4):
    addend = sum(nums[:i+1])
    augend = nums[i+1]
    print(f'{addend} + {augend} = {addend+augend}')

Output

Enter 1st 4-digit no.: 9999
The fourth sum will be the concatenation of:
  2
  ⌊9999/10⌋ = 999
  mod(9999 - 2, 10) = 7
= 29997

Enter 2nd 4-digit no.: 2345
The 3rd 4-digit no. is 9999 - 2345 = 7654
Enter 4th 4-digit no.: 6789
The 5th 4-digit no. is 9999 - 7654 = 3210

So,
9999 + 2345 = 12344
12344 + 7654 = 19998
19998 + 6789 = 26787
26787 + 3210 = 29997
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.