本文共 725 字,大约阅读时间需要 2 分钟。
条件判断与缩进,注意冒号
加次数限制#猜数字lucky_num = 19input_num = -1#次数限制
count = 0#while lucky_num!=input_num and count < 3:while count < 3:input_num = int(input("please input your lucky_num:"))if input_num < lucky_num:print("please input big num")elif input_num > lucky_num:print("please input little num")else:print("great")breakcount += 1print(count)else:print("too many counts!!!!")注意缩进,python是对缩进敏感的语言注释:ctrl+/for循环
#次数限制for i in range(3):input_num = int(input("please input your lucky_num:"))if input_num < lucky_num:print("please input big num")elif input_num > lucky_num:print("please input little num")else:print("great")breakelse:print("too many counts!!!!")转载于:https://blog.51cto.com/11test/2068891