码迷,mamicode.com
首页 > 编程语言 > 详细

Python学习记录-2016-11-30

时间:2016-11-30 23:17:16      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:记录

今日内容:

猜年龄游戏和游戏优化:

依照上次代码:

age = 22

guess_num = int(input("input your guess number:"))

if guess_number == age:

    print("Congratulation,you got it!")

elif guess_number > age:

    print("Think smaller!")

else:

    print("Think bigger")

加入循环10次

age = 22

for i in range(10)

guess_num = int(input("input your guess number:"))

if guess_number == age:

    print("Congratulation,you got it!")

elif guess_number > age:

    print("Think smaller!")

else:

    print("Think bigger")

10次中三次猜不中退出:

age = 22

for i in range(10)

    if i < 3

        guess_num = int(input("input your guess number:"))

        if guess_number == age:

            print("Congratulation,you got it!")

            break#猜中退出全部循环

        elif guess_number > age:

            print("Think smaller!")

        else:

            print("Think bigger")

    else:

        print("To many attampts")

        break

10次中三次猜不中继续重新猜:

age = 22

counter == 0

for i in range(10)

    if counter < 3

        guess_num = int(input("input your guess number:"))

        if guess_number == age:

            print("Congratulation,you got it!")

            break#猜中退出全部循环

        elif guess_number > age:

            print("Think smaller!")

        else:

            print("Think bigger")

    else:

            #print("To many attampts")

            #break

    continue_confirm = input("Do you want to continue?")

    if continue == "yes"

        counter = 0

        continue#跳出当前循环

    else:

        break

    counter +=1#counter = counter +1

    

        

Python学习记录-2016-11-30

标签:记录

原文地址:http://12306114.blog.51cto.com/12296114/1878327

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!