编写程序-采用Whlie循环计算 猜数字

这里写自定义目录标题

采用Whlie循环计算

print("令狐大侠说他喝了若干杯酒,\
      杯数满足条件:三三数之剩二,\
 五五数之剩三,七七数之剩二,\
  问令狐大侠究竟喝了多少杯酒?")
cups = 1
flag = True
while flag:
    if cups % 3 == 2 and cups % 5 == 3 and cups % 7 == 2:
        print("朋友,令狐大侠喝了{}杯酒!".format(cups))
        flag = False
    cups = cups + 1
#第二种方法
cups = 1
while True:
    if cups % 3 == 2 and cups % 5 == 3 and cups % 7 == 2:
        print("朋友,令狐大侠喝了{}杯酒!".format(cups))
        break
    cups = cups + 1

猜你喜欢

转载自blog.csdn.net/m0_62491934/article/details/121208408