2020-10-22-python学习成长记001

it2025-06-21  9

```python ```python ```python #Author:Tim guess_number = "30" #需要猜的数字 count = 0 #猜测次数 while count <3: #少于3次,一直循环,直至3次,停止循环 input_number = input("number:") print(type(input_number)) if input_number == guess_number:`在这里插入代码片` print ("guess right") break elif input_number > guess_number: print("guess is bigger,think smaller") else: print( "guess is smaller,think bigger" ) count = count + 1 #csount+=1 if count == 3: #判断输入超过3需要重新执行 num_input = 0 while num_input <3: #有三次输入y or n 的机会 confirm_value = input("do you want to keep guessing,Please input y or n") if confirm_value == 'y': num_input = num_input + 4 #任意加值,大于3即可 count = 0 #进入猜数字循环 if confirm_value == 'n': break if confirm_value != 'y' and confirm_value != 'n': #判断是否输入y或者r num_input = num_input + 1 continue else: print("you have try many times") #超过三次则退出
最新回复(0)