Python Forum
reverse math in python, who will find the correct answer?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reverse math in python, who will find the correct answer?
#1
'''
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
Reply
#2
Is there question here? It's completely unclear what your goal is.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Jan-10-2021, 05:05 PM)buran Wrote: Is there question here?
Yes
Reply
#4
Wall Wall Wall Wall Wall Wall Wall Wall
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(Jan-10-2021, 05:07 PM)buran Wrote: Wall Wall Wall Wall Wall Wall Wall Wall

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
25 * 99
27 * 58
Reply
#6
(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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
(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
Reply
#8
Replace (b + d)*a by a*d + b*c and it will work.
Kakha likes this post
Reply
#9
(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
Reply
#10
Note that
D1=sum1 % 10
D1_Memo= sum1 // 10
can be shortened in
D1_Memo, D1 = divmod(sum1, 10)
Kakha likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Answer for newbie, Sqlite3 Froger 2 849 Sep-27-2023, 05:33 PM
Last Post: noisefloor
  Coding answer for newbie cg3 2 1,145 Aug-05-2023, 12:17 PM
Last Post: jefsummers
  First Day using Python. NEED Simple Math CODE HELP! Jesseluke 4 1,362 Jan-13-2023, 01:04 PM
Last Post: jefsummers
  how to reverse a list and store in another list in python SuperNinja3I3 6 3,277 Aug-14-2022, 06:36 PM
Last Post: DeaD_EyE
  Reverse Function in Python Voraman 7 3,259 Feb-13-2021, 07:21 PM
Last Post: Voraman
  What am I doing wrong to not get the answer pav1983 7 3,700 Jun-25-2020, 08:53 PM
Last Post: ndc85430
  Need help with an assignment, not an answer. celtickodiak 4 2,938 Oct-01-2019, 02:04 PM
Last Post: jefsummers
  Math problem in Python - pyqt5 rwahdan 6 5,706 Jun-18-2019, 08:11 PM
Last Post: Gribouillis
  How to correct the Python programming - Support Vector Machine vokoyo 7 4,422 Apr-06-2019, 10:11 AM
Last Post: scidam
  What's the full answer to this question in python? (bayesian decision theory) Hblaugrana 1 2,475 Oct-31-2018, 02:22 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020