笨办法33while循环

Posted p36606jp

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了笨办法33while循环相关的知识,希望对你有一定的参考价值。

改了之前的代码,加入while:

 1 #coding: utf-8
 2 print("王小狗丑不丑?丑→1;不丑→2")
 3 answer = input(">")
 4 if answer == "1":
 5     print("恭喜你,你的选择很正确!")
 6 
 7 elif answer == "2":
 8     print("要不,你再考虑一下? ")
 9     print("王小狗究竟丑不丑?丑→1;不丑→2")
10     real_answer = input(">")
11     while real_answer != "1" and real_answer != "2" :
12         print("别捣乱!王小狗丑不丑?丑→1;不丑→2")
13         real_answer = input(">")
14     while real_answer == "2" or real_answer != "1":
15         print("我觉得差不多了,你就说王小狗到底丑不丑?丑→1;不丑→2")
16         real_answer = input(">")
17         if real_answer == "2":
18             print("说这种话,你自己信吗!")
19         elif real_answer == "1":
20             pass
21         else:
22             print("请你认真回答。")
23     print("恭喜你,可以去睡觉了!")
24 
25 else:
26     print("不好好做题,你想作甚王小丑!")
27     print("请重新回答,王小狗丑不丑?丑→1;不丑→2")
28     last_answer = input(">")
29     while last_answer != "1" and last_answer != "2":
30         print("快回答!王小狗丑不丑?丑→1;不丑→2")
31         last_answer = input(">")
32     while last_answer == "2" or last_answer != "1":
33         print("无论如何,王小狗丑不丑?丑→1;不丑→2")
34         last_answer = input(">")
35         if last_answer == "2":
36             print("不能因为你的善良而埋没了良知!")
37         elif last_answer == "1":
38             pass
39         else:
40             print("你踏马好好回答行不行?")
41     print("恭喜你,可以去睡觉了!")
42 
43 input()

 

以上是关于笨办法33while循环的主要内容,如果未能解决你的问题,请参考以下文章

笨办法学Python(三十六)

笨办法32循环和列表

笨办法学Python(三十九)

ex33 while 循环

笨办法学Python(三十二)

比较“笨”的枚举算法