python作业是什么_自学python第一天,基础作业。

1. 判断下列逻辑语句的True,False.

1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6

2)not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6

2. 求出下列逻辑语句的值。

1),8 or 3 and 4 or 2 and 0 or 9 and 7

2),0 or 2 and 3 and 4 or 6 and 0 or 3

3. 下列结果是什么?

1)、6 or 2 > 1

2)、3 or 2 > 1

3)、0 or 5 < 4

4)、5 < 4 or 3

5)、2 > 1 or 6

6)、3 and 2 > 1

7)、0 and 3 > 1

8)、2 > 1 and 3

9)、3 > 1 and 0

10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2

4. while循环语句基本结构?

python

while 条件:

循环体

5. 利用while语句写出猜大小的程序:

设定一个理想数字比如:66,让用户输入数字,如果比66大,则显示猜测的结果大了;如果比66小,则显示猜测的结果小了;只有等于66,显示猜测结果正确,然后退出循环。

a = int(input('请输入要猜的数字'))

if a == 66:

print('猜测结果正确')

elif a < 66:

print('猜小了,请往大点猜')

elif a > 66:

print('猜大了,请往小点猜')

6. 在5题的基础上进行升级,给用户三次猜测机会,如果三次之内猜测对了,则显示猜测正确,退出循环,如果三次之内没有猜测正确,则自动退出循环,并显示‘太笨了你....’。

count = 1

while count < 4:

num = int(input('请输入数字:'))

if num > 66:

print('猜大了')

elif num < 66:

print('猜小了')

else:

print('恭喜你猜对了')

break

count += 1

else:

print('太笨了')

7. 使用while循环输出 1 2 3 4 5 6 8 9 10

count = 1

while count < 11:

if count == 7:

print('')

else:

print(count)

count += 1

#

count = 1

while count < 11:

if count == 7:

pass

else:

print(count)

count += 1

#

count = 1

while count < 11:

if count == 7:

count += 1

print(count)

count += 1

#

count = 0

while count < 10:

count += 1

if count == 7:

continue

print(count)

#

#

#

8. 求1-100的所有数的和

a = 0

b = 0

while a < 100:

a += 1

b = b + a

print(b)

9. 输出 1-100 内的所有奇数

a = 1

while a < 100:

print(a)

a += 2

10. 输出 1-100 内的所有偶数

a = 0

while a < 99:

a += 2

print(a)

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

count = 1

s = 0

while count < 100:

if count % 2 == 0:

s = s - count

else:

s = s + count

count += 1

print(s)

12. 用户登录(三次输错机会)且每次输错误时显示剩余错误次数(提示:使用字符串格式化)

count = 1

while count <= 3:

username = input('用户名')

password = input('密码')

if username == 'alex' and password == '123':

print('登录成功')

else:

print('用户名或者密码错误,还剩%s机会' % (3 - count))

count = count + 1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值