python:一些简单算法练习(0)
1.输出1,2,3,4,5,6,8,9,10
n = 1 while n < 11: if n == 7: pass else: print(n) n += 1
2.求1-100所有数的和
x = 1 y = 0 while x < 101: y = y + x x += 1 print(y)
3.输出1-100内所有的奇数
x = 1 while x < 101: if x % 2 == 1: print(x) else: pass x += 1
4.求1-2+3-4+5-6+7-.......+99-100的和
x = 1 y = 0 while x < 101: if x % 2 == 1: y += x else: y -= x x += 1 print(y)
5.用户登录3次(3次重新登录的机会)
x = 0 while x < 3: name = input('小明的英文编码是:') if name == 'xiaoming': pass else: x += 1
6.输出输入的字符的每一个单个字符的索引和对应的字符
test = input('请输入:') for item in range(0, len(test)): print(item, test[item]) # 执行: # 请输入:werty # 0 w # 1 e # 2 r # 3 t # 4 y