程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python Einstein ladder problem

編輯:Python

Einstein's ladder problem

· Einstein's ladder problem : There is a ladder , Each step 2 rank , Last remaining 1 rank ; Each step 3 rank , Last remaining 2 rank ; Each step 5 rank , Last remaining 4 rank ; Each step 6 rank , Last remaining 5 rank ; Only every step 7 Step time , Just to the top of the stairs . Ask how many steps there are at least ?
Required while Loop statement

analysis

  1. set up 1000 The minimum number of steps can be input internally ,
  2. Because every step 2 rank , Last remaining 1 rank ; Each step 3 rank , Last remaining 2 rank ; Each step 5 rank , Last remaining 4 rank ; Each step 6 rank , Last remaining 5 rank ; Only every step 7 Step time , Just to the top of the stairs .
    So for
    (x % 2 == 1) and (x % 3 == 2) and (x % 5 == 4) and (x % 6 == 5) and (x % 7 ==0)

Code

x = 1
while x < 1000: # set up 1000 The minimum number of steps can be input internally 
if (x % 2 == 1) and (x % 3 == 2) and (x % 5 == 4) and (x % 6 == 5) and (x % 7 ==0):
print(' At least ',x,' Step ladder ')
x += 1
break # Out of the loop 
else:
x += 1
print(" The loop ends ")

Output results


There are different views that can be discussed in the message below (^ - ^)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved