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:\Users\Martin\Desktop\python_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)