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

python练习

时间:2015-12-17 19:24:44      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:python

练习1

让用户一直输入数字,如果输入的不是数字就报错,如果输入pc就退出并算出数字之和

#!/usr/bin/evn python
total = 0
while True:
    input = raw_input(‘input something: ‘)
    if input.isdigit():
        total += int(input)
    elif input == ‘pc‘:
        break
    else:
        print "error"
print total


本文出自 “不抛弃!不放弃” 博客,请务必保留此出处http://thedream.blog.51cto.com/6427769/1725722

python练习

标签:python

原文地址:http://thedream.blog.51cto.com/6427769/1725722

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