zoukankan      html  css  js  c++  java
  • 小甲鱼Python第六讲课后习题

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

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

    1.0

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

    a<b and b<c

    2.不使用IDLE,你可以轻松说出5**-2的值么?

    1/25

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

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

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

    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('在程序限定的范围内找不到答案!')
  • 相关阅读:
    玩转动态编译
    [源码]RandomId 生成随机字符串
    玩转动态编译:四、封装
    玩转动态编译:三、提高性能,抛弃反射
    玩转动态编译:一、初识
    封装和内置函数property classmethod staticmethod
    面向对象--命名空间和组合
    初始面向对象
    模块之序列化模块和包
    模块 time模块 sys模块 os模块
  • 原文地址:https://www.cnblogs.com/jieperhaps/p/9002001.html
Copyright © 2011-2022 走看看