[英]Solving this kata from codewars ,any tips/fixing ? (new to python)
[英]Does anyone have any tips on how to solve this Codewars Kata to find squares from rectangle?
我正在将矩形代码战争变成正方形 Kata。 我对 python 很陌生,只是想学习。
目的是将给定的长度和宽度分成正方形: https://www.codewars.com/kata/55466989aeecab5aac00003e/train/python
这就是我到目前为止所拥有的。 我不知道如何确定正方形是否适合矩形。 任何提示将不胜感激。
def sqInRect(lng, wdth):
solution = []
b = (lng * wdth) - (wdth**2)
solution.append(wdth)
print(b)
if lng == wdth:
return None
else:
for i in range(wdth,0,-1):
print("i is " + str(i))
if b - (i**2) > 0:
if wdth + i <= lng:
solution.append(i)
b = b- i**2
print("Yes!")
print(b)
if b-(i**2) >= 0:
solution.append(i)
b = b - (i**2)
print("DOne")
print(b)
return solution
只要有条不紊,一步一步地去做。
def sqInRect(length, width):
sizes = []
while length and width:
side = min(length,width)
sizes.append(side)
print( "%dx%d" % (side,side) )
if length == side:
width -= side
else:
length -= side
return sizes
print(sqInRect(5,3))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.