python基础2

#基本操作运算符
a = 10
b = 20
c = 3
print(a**b,b/c,b//c)#a的b次幂 除法 除法取整

#逻辑控制
'M' in "MMMMMM"#成员运算符 is 是身份运算符
def user_login():
    password = input('password:')
    if password == '123':
        print('Login  success')
    else:
        print('Login failed,error:password wrong')
        user_login()

user_login()

#for循环
for item in 'Hello World':
    print(item)

total_num = 0
for num in range(1,11):
    total_num += num
    print(total_num)

for i in range(1,10):
    for j in range(1,10):
        print('{}*{}={}'.format(i,j,i*j))

#创建10个文件以数字命名
def create_txt_file(num):
    name = None
    for i in range(1,num+1):
        name = '%d' %i#数字转字符串
        path = '/Users/cykj/DeskTop/'+ name+'.txt'
        file = open(path,'w')
        print('Create Done')
        file.close

create_txt_file(10)


#利滚利
def invest(money,year,rate):
    curr_money = money
    for i in range(1,year+1):
        total_money = curr_money*(1+rate);
        print(total_money)
        curr_money = total_money

invest(100,5,0.05)

#求和sum
a_list = [1,2,3];
print(sum(a_list))

#random伪随机
import  random
point1 = random.randrange(1,10)
point2 = random.randrange(1,10)
point3 = random.randrange(1,10)
print(point1,point2,point3)
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/win_mary/article/details/77510130
文章标签: Python
个人分类: Python
上一篇python基础1
下一篇python基础3
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭