zoukankan      html  css  js  c++  java
  • python基础 练习题


    【练习题1】实现一个整数加法计算器
    如 content = input(">>> ") # 5+9 , 6+4
    count=0
    while 1:
        content=input('>>>')
        s1 = content.split('+')
        print(s1)
        count = 0
        for i in s1:
            count += int(i)
        print(count)
    【练习题2】请编写1 - 100 所有数的和
    sum=0
    for i in range(1,101):
        print(i)
        sum+=i
    
    print(sum)
    【练习题3】有如下值集合[11,22,33,44,55,66,77,88,99,90],将所有大于66的值保存至字典的第一个key中,将小于66的值保存至第二个key的值中。
    即:{'k1':大于66的所有值,'k2':小于66的所有值}
    li=[11,22,33,44,55,66,77,88,99,90]
    dic={}
    l1=[]
    l2=[]
    for i in li:
        if i ==66:
            continue
        elif i>66:
            l1.append(i)
    
        else:
            l2.append(i)
    
    dic.setdefault('k1',l1)
    dic.setdefault('k2',l2)
    
    print(dic)
    【练习题4】编写9*9乘法表
    print('---张氏99乘法表---')
    for i in range(1,10):
        for j in range(1,i+1):
            print(j,"*",i,'=',i*j,end='	')
        print()
    【练习题5】 使用while,完成以下图形的输出
    '''
    *
    * *
    * * *
    * * * *
    * * * * *
    * * * *
    * * *
    * *
    *
    '''
    i=1
    while i<=5:
        print( '* '*i)
    
        i+=1
    
    i=4
    while 0<i<=4:
        print('* '*i )
    
        i-=1
  • 相关阅读:
    CSS切割
    一台电脑 多个 tomcat
    CGI
    电源关系
    Monkey Test 命令使用
    html ul
    java 反射
    RTMP
    动态库
    flash 大文件上传
  • 原文地址:https://www.cnblogs.com/hanfe1/p/10795062.html
Copyright © 2011-2022 走看看