zoukankan      html  css  js  c++  java
  • while循环初探

     1 count = 0
     2 #while True:
     3 while count < 3:
     4     count +=1           #count每次加1
     5     guess_number = int(22)
     6     get_number = int(input('Please enter the number you guessed>>>'))
     7 
     8     if guess_number == get_number:
     9         print("Congratulations, you guessed it")
    10         exit()
    11     elif guess_number > get_number:
    12         print("The number you guessed is too small")
    13     else:
    14         print("The number you guessed is too big")
    15 else:
    16     print('too many times')  #上面条件不满足的时候打印

     #while 更改版当猜数字在第三次时询问是否继续游戏

     1 count = 0
     2 while True:
     3     guess_number = int(22)
     4     get_number = int(input('Please enter the number you guessed>>>'))
     5 
     6     if guess_number == get_number:
     7         print("Congratulations, you guessed it")
     8         exit()
     9     elif guess_number > get_number:
    10         print("The number you guessed is too small")
    11     else:
    12         print("The number you guessed is too big")
    13     count += 1
    14     if count == 3:
    15         a = input("You guessed it three times.Do you want to continue playing this game?[N/Y]")
    16         if a == 'n' or a == 'N':
    17             print('That is a pity!!')
    18             exit()
    19         else:
    20             count = 0
    21             continue
  • 相关阅读:
    笔记2-斐波那契数列
    笔记1-排序
    C++ 顶层const和底层const ?
    C++指针常量与常量指针的区别?
    C++指针和引用的区别?
    函数指针, 指针函数?
    手机横竖屏问题
    Swift
    Swift 渐变色
    Swift guard 关键字
  • 原文地址:https://www.cnblogs.com/jesse-gong/p/7615148.html
Copyright © 2011-2022 走看看