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

Use Python to solve the problem of Hanxin ordering soldiers, and write a program to calculate how many soldiers Hanxin has at least?

編輯:Python

【 Problem description 】 In the history of Chinese mathematics , There is a widespread “ Han Xin orders soldiers ” The story of : Han Xin is a general under Liu Bang, the emperor of the Han Dynasty , He is brave and good at war , Resourceful , He made outstanding contributions to the Han Dynasty . It is said that Han Xin's math level is also very excellent , When he was ordering troops , To know how many soldiers , While keeping military secrets , Then let the soldiers line up to count off :

 Press from 1 to 5 Number off , Write down the number reported by the last soldier as 1; Press again from 1 to 6 Number off , Write down the number reported by the last soldier as 5; Press again from 1 to 7 Number off , Write down the number reported by the last soldier as 4; Finally, press from 1 to 11 Number off , The last soldier reported 10;

Please write a program to calculate how many soldiers Han Xin has at least .

Input format :

No input for this question

Output format :

Output the number of soldiers Han Xin has at least .

The title is as above , I really don't know how to define the scope , The program always reports errors. I don't know why .




Take the answer :
flag=0sum=6while(flag!=4): if (sum % 5 == 1): flag=1; else: sum=sum+1 continue if (sum % 6 == 5 and flag == 1): flag = 2; else: sum = sum + 1 continue if (sum % 7 == 4 and flag == 2): flag = 3; else: sum=sum+1 continue if (sum % 11 == 10 and flag == 3): flag = 4; else: sum = sum + 1 continueprint(sum);


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