python基础作业练习-20171214

Posted jason.lv

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python基础作业练习-20171214相关的知识,希望对你有一定的参考价值。

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

count = 1 

while count <= 10:
    if count == 7:
        count = count + 1
        continue
    print(count)
    count = count + 1

2、求1-100的所有数的和

count = 1 
sum = 0

while count <= 100:
	sum = sum + count
	count = count + 1 

print(sum)

3、输出 1-100 内的所有奇数

count = 1 

while count <= 100:
	if count % 2 ==1:
		print(count)
		count = count + 1
	count = count + 1

4、输出 1-100 内的所有偶数

count = 1

while count <= 100:
	if count % 2 ==0:
		print(count)
		count = count + 1
	count = count + 1

5、求1-2+3-4+5 ... 99的所有数的和

count = 1 
sum = 0 

while count <= 99:
	if count ==1:
		sum = count
		count = count + 1
		continue
	else:
		if count % 2 ==1:
			sum = sum + count
			count = count + 1
		else:
			sum = sum - count
			count = count + 1
print(sum)

6、用户登陆(三次机会重试)

count = 1
sum = 0

while count <= 3:
	username = input(‘请输入用户名:‘)
	password = input(‘请输入用户密码:‘)
	if username == ‘Jason‘ and password == ‘123‘:
		print(‘登录成功,欢迎“Jason”回来!‘)
		break
	else:
		sum = 3 - count
		print(‘用户名或密码错误,请重新输入,目前还剩余‘+str(sum)+‘机会!‘)
		count = count + 1

 

以上是关于python基础作业练习-20171214的主要内容,如果未能解决你的问题,请参考以下文章

作业2——python基础练习

作业2-Python基础练习

python基础之作业3----三级菜单小练习

python基础之作业1----购物车小练习

Python基础综合练习

Python matplotlib 基础练习:画出正弦曲线等