Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.5 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
696655d24b614176d4c9b78b Challenge 168: Scaled Image 29 challenge-168

--description--

Given a string representing the width and height of an image, and a number to scale the image, return the scaled width and height.

  • The input string is in the format "WxH". For example, "800x600".
  • The scale is a number to multiply the width and height by.

Return the scaled dimensions in the same "WxH" format.

--hints--

scale_image("800x600", 2) should return "1600x1200".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_image("800x600", 2), "1600x1200")`)
}})

scale_image("100x100", 10) should return "1000x1000".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_image("100x100", 10), "1000x1000")`)
}})

scale_image("1024x768", 0.5) should return "512x384".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_image("1024x768", 0.5), "512x384")`)
}})

scale_image("300x200", 1.5) should return "450x300".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_image("300x200", 1.5), "450x300")`)
}})

--seed--

--seed-contents--

def scale_image(size, scale):

    return size

--solutions--

def scale_image(size, scale):
    width, height = map(int, size.split("x"))

    new_width = round(width * scale)
    new_height = round(height * scale)

    return f"{new_width}x{new_height}"