小甲鱼Python第六讲课后习题

python中被看做假:FALSE  none 0  ‘ ’  " "  ( ) [ ] { },其余一切都被解释为真python

0.Python 的 floor 除法如今使用“//”实现,那3.0//2.0您目测会显示什么内容?spa

1.0code

 

1.a<b<c 事实上等于?blog

a<b and b<cclass

 

2.不使用IDLE,你能够轻松说出5**-2的值么?bfc

1/25程序

 

3.如何简单判断一个数是奇数仍是偶数?im

模2取余,等于0为偶数,等于1为奇数img

 

4.请用最快速度说出答案:not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9di

4

逻辑运算符的优先次序:not>and>or

 

动手

1.打印1-100偶数、奇数

num =100

while num:

  if num%2==0:

    print("偶数为:%s"+%num)

  else:

    print('奇数为:%s'+%num)

  num -=1

 

附加

print("输出0~100全部的奇数")
for i in range(100):
    if i%2 == 1:
        print(i)

 

2.

i = 1
x = 7
flag = 0

while i < 100:
    i = i + 1
    if (x%2==1)and(x%3==2)and(x%5==4)and(x%6==5):
        flag = 1
    else:
        x = 7*i
if flag ==1:
    print("阶梯数是:",x)
else:
    print("请扩大范围!")

附小甲鱼源代码:

复制代码
x = 7
i = 1
flag = 0

while i <= 100:
    if (x%2 == 1) and (x%3 == 2) and (x%5 == 4) and (x%6==5):
        flag = 1
    else:
        x = 7 * (i+1) # 根据题意,x必定是7的整数倍,因此每次乘以7
    i += 1

if flag == 1:
    print('阶梯数是:', x)
else:
    print('在程序限定的范围内找不到答案!')
相关文章
相关标签/搜索