# digit containing 9 has to be greater or equal in length
mul9 = { str(i): str(9-i) for i in range(10)}
print(f"{mul9}\n")
number1 = int(input("Enter 9s': "))
len1 = len(str(number1))
number2 = int(input(f"Enter (0 - {str(9)*len1}): "))
if len(str(number1)) < len(str(number2)):
print("This trick won't work")
else:
res = str(number2 - 1)
print(f"{number2} - 1 = {res} ")
end = ''
for i in res:
end += mul9[i]
print(f"{i} needs {mul9[i]} to become 9")
res += (len(str(number1)) - len(str(number2))) * "9" + end # This accounts for adding the invisible 0s at the start of 'res' in the video. I've simply added the correct number of 9s and avoided but avoided looping through them in the for loop.
print(res)
gives
{'0': '9', '1': '8', '2': '7', '3': '6', '4': '5', '5': '4', '6': '3', '7': '2', '8': '1', '9': '0'}
Enter 9s': 99
Enter (0 - 99): 99
99 - 1 = 98
9 needs 0 to become 9
8 needs 1 to become 9
9801
[Program finished]
The objective of the code is to demo students how we can multiply large numbers in smallest amount of time. I am new to python so not that aware of syntax. Works as expected. Can you please point out at lines which can be reduced.