首页 > 编程语言 > 详细

Python自学起飞——003

时间:2015-02-09 07:09:34      阅读:229      评论:0      收藏:0      [点我收藏+]

    在前面的尝试过程中没有什么甜头,多么无聊的输出预定义的内容,接下来说写点活的,真正感受一下程序的魅力:


    在python中提供了raw_input

>>> name = raw_input("what is you name? ")
what is you name? yuefan
>>> print name
yuefan


    感觉有点意思啦,接下来玩个猜数字游戏遛遛:

# cat magic_num.py
#/usr/bin/env python
#coding: utf-8

a = 15
guess = 0

while a != guess:
    guess = input("猜数字,输入个数字试试: ")
    # print a,type(a), guess, type(guess)
    if guess < a:
        print "不对,小啦。\n"
    elif guess > a:
        print "不对,大啦。\n"

print "不错啊,搞对啦!!!!"


这个可以让我的儿子玩玩啦,接下来把电脑时间交给儿子……

Python自学起飞——003

原文:http://yuefan.blog.51cto.com/9907408/1612821

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!