您的位置:首页 > 编程语言 > Python开发

Python 基础练习01

2016-07-17 22:29 465 查看
#!/usr/local/bin/python
#encoding:utf-8

# i= 0
# while i<20:
#     print i
#     i+=1
# print 'end'

'''
y = raw_input('please input a number:')

while not y:
y = raw_input('please input a number !!!!!:')
print int(y)/2.0
'''

'''
小练习 2
让用户一直输入数字
如果输入的是'0',终止程序
打印所有数字之和
'''

# c=int(raw_input('Please enter a number:'))
# count=0
# while c:
#     count = count + c
#     c = int(raw_input('Please enter a number:'))
# print 'The total num is %s'% count

'''
小练习 3
让用户一直输入数字(只输入数字)
如果没有输入任何值,终止程序
打印所有输入数字的平均值
'''
# y = raw_input('please input a number: ')
# count = 0
# times = 0.0
# while y:
#     count = count + int(y)
#     y = raw_input('please input a number !!!!!:')
#     times += 1
# print 'the avage num is %s' %(count/times)

'''
小练习 4
存10000块钱,年利率是3.25%
求多少年之后,存款能翻番
'''

# money = 10000
# rate = 0.0325
# Years=0
# while money<20000:
#     money=money * (1+rate)
#     Years=Years+1
# print 'Years is %s, Money is %s' % (Years,money)

'''
for循环
'''
# arr= ['chris','alvin','sherman',123,True]
# for i in arr:
#     print '%s is the member of arr' % (i)

'''
小练习 5
遍历一个序列['C','js','python','js','css','html','node']
统计这个序列中,js出现的次数
'''
arr = ['C','js','python','js','css','html','node']
times = 0
for i in arr:
if i=='js':
times+=1
print times
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: