zoukankan      html  css  js  c++  java
  • python 小练习1

    _input = ['I',6,6,'love','python',6]


    _str = '' _sum = 0 for item in _input: if isinstance(item,str): _str += item _str += ' ' elif isinstance(item,int): _sum += item else: print('nothing') print(_str) print(_sum)

    实现输出2-3+4-5+6.....+100

    _sum = 0
    for item in range(2,101):
        if item % 2 == 0:
            _sum += item
        else:
            _sum -= item
        
    print(_sum)

     使用while循环输入 1 2 3 4 5 6     8 9 10

    i = 0
    
    while i < 10:
        i += 1
        if i ==7:
            continue
        else:
            print(i)

     

    #coding:gbk
    
    f = open(r'C:UsersMartinDesktoppython_class_members.txt')
    
    content = f.readlines()
    
    while True:
        _input = input('pls input your choise:')
        if _input == 'all':
            for line in content:
                print(line)
        elif _input in ['quit','exit','q']:
            exit()
            
        elif "-" in _input:
            prefix,suffix = _input.split('-')
            for line in content[int(prefix) - 1:int(suffix)]:
                print(line)
        
        elif _input not in str(content):
            print('sorry, your input is not in search')
        
        
        else:
            for item in content:
                if _input in item:
                    print(item)

     

  • 相关阅读:
    《算法竞赛入门经典》(刘汝佳)——排序与检索(基础)
    Python中的GIL
    MongoDB 安装
    python3 报错集合
    socket 实例化方法
    socket入门
    Day_6作业_模拟人生
    高阶函数举例
    面向对象_python
    xml
  • 原文地址:https://www.cnblogs.com/hellojackyleon/p/8705640.html
Copyright © 2011-2022 走看看