'''
this formula is calculated from right to left, but only if a = c, for example: 11 * 15, 55 * 59, 97 * 92
who can change the formula so that it counts when a != c for example: 11 * 35, 55 * 19, 97 * 42
(a b c d < 10)
'''
a = 1
b = 2
c = a
d = 9
sum1 = b * d
D1=sum1 % 10
D1_Memo= sum1 // 10
sum2 =(b+d)*a + D1_Memo
D2=sum2 % 10
D2_Memo= sum2 // 10
D3 = a * c + D2_Memo
print(a,b,"*",c,d,"=",D3,D2,D1)
Output:
1 2 * 1 9 = 2 2 8
Is there question here? It's completely unclear what your goal is.
(Jan-10-2021, 05:15 PM)Kakha Wrote: [ -> ]the function calculates all multiplications for numbers 0-99 that start with the same digit
you need to get a formula that works for all numbers 0-99 that don't start with the same digit
there is NO function present in your code.
And we don't need to do anything - it's you [home]work. If you want help, help us to help you, don't make us guess.
(Jan-10-2021, 05:19 PM)buran Wrote: [ -> ] (Jan-10-2021, 05:15 PM)Kakha Wrote: [ -> ]the function calculates all multiplications for numbers 0-99 that start with the same digit
you need to get a formula that works for all numbers 0-99 that don't start with the same digit
there is NO function present in your code.
And we don't need to do anything - it's you [home]work. If you want help, help us to help you, don't make us guess.
this is a question for mathematicians
Replace (b + d)*a
by a*d + b*c
and it will work.
(Jan-10-2021, 06:29 PM)Gribouillis Wrote: [ -> ]Replace (b + d)*a
by a*d + b*c
and it will work.
'''
thanks Gribouillis it works !!!
'''
a = 1
b = 5
c = 9
d = 4
sum1 = b * d
D1=sum1 % 10
D1_Memo= sum1 // 10
sum2 =a*d + b*c + D1_Memo
D2=sum2 % 10
D2_Memo= sum2 // 10
D3 = a * c + D2_Memo
print(a,b,"*",c,d,"=",D3,D2,D1)
Output:
1 5 * 9 4 = 14 1 0
Note that
D1=sum1 % 10
D1_Memo= sum1 // 10
can be shortened in
D1_Memo, D1 = divmod(sum1, 10)