zoukankan      html  css  js  c++  java
  • 笨办法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()

     精简:

     1 #coding: utf-8
     2 print("王小狗丑不丑?丑→1;不丑→2")
     3 answer = input(">")
     4 while answer !='1':
     5     if answer=='2':
     6         print("回答错误,请重新输入")
     8     else:
     9         print("别瞎搞,好好回答")
    11     answer = input(">")
    12 print("恭喜你,答对了!")
    13 input()

     注:因为是做给人玩的小游戏,导出exe文件,结尾input(),使运行框不关闭

  • 相关阅读:
    1026 Table Tennis (30)
    1029 Median
    1025 PAT Ranking (25)
    1017 Queueing at Bank (25)
    1014 Waiting in Line (30)
    1057 Stack (30)
    1010 Radix (25)
    1008 Elevator (20)
    字母大小写转换
    Nmap的基础知识
  • 原文地址:https://www.cnblogs.com/p36606jp/p/8137891.html
Copyright © 2011-2022 走看看