Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

For a given number of horseshoes p and number of horses k

I’ve completely stuck with this task and I really dunno how to make this program work properly, because I think I’ve already tried many possible options, but it still unfortunately didn’t work successfully.

The task is: "The blacksmith has to shoe several horses and needs to see if he has the correct number of horseshoes. Write a check(p, k) function that, for a given number of horseshoes p and number of horses k, prints out how many horseshoes are missing, remaining, or whether the number is correct (see sample file for output format)."

The code I’ve already done is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def check(p, k):
    if p % 2 == 0 and k % 2 == 0 and p % k == 0:
        print("Remaining:", k % p)     
    elif p % k != 0:
        print("Missing:", p // k + 1)
    else:
        print("OK")

check(20, 6)
check(10, 2)
check(12, 3)
check(13, 3)

The output should look like this:

Missing: 4
Remaining: 2
OK
Remaining: 1

>Solution :

You could try this:

def check(shoes, horses):
  if shoes > 4*horses:
     print("Remaining:", shoes - 4 * horses)
  elif shoes == 4*horses:
     print("OK")
  else:
     print("Missing:", 4 * horses - shoes)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading