缩短Python中的许多if子句(Shorting down many if clauses in Python)
我有这个代码,我想把它扩展到一个非常高的数量,但它在我做它的方式是非常低效...也许这里有一个人知道一个简单的方法来缩短它。
if draw_x+draw_x1>50: space_x=10 if draw_x+draw_x1>500: space_x=100 if draw_x+draw_x1>5000: space_x=1000 if draw_x+draw_x1>50000: space_x=10000 if draw_x+draw_x1>500000: space_x=100000 if draw_x+draw_x1>5000000: space_x=1000000I've got this code and i want to extend it to a veryhigh amount but it is veryy inefficient in the way I'm doing it... Maybe some one here knows a easy way to short it down.
if draw_x+draw_x1>50: space_x=10 if draw_x+draw_x1>500: space_x=100 if draw_x+draw_x1>5000: space_x=1000 if draw_x+draw_x1>50000: space_x=10000 if draw_x+draw_x1>500000: space_x=100000 if draw_x+draw_x1>5000000: space_x=1000000最满意答案
怎么样:
space_x = 10**int(math.log10((draw_x+draw_x1)//5))How about:
space_x = 10**int(math.log10((draw_x+draw_x1)//5))更多推荐
发布评论