1. show you the code

      1. ans = input("最近学习了吗?yes/no: ")
      2. while ans == 'yes':
      3. print("very good\n1.Python\n2.高数\n3.退出")
      4. selection = input("请输入学习选项: ")
      5. if selection == '1':
      6. print("Python真不戳!")
      7. elif selection == '2':
      8. print("高数真难啊...")
      9. elif selection == '3':
      10. print("已退出")
      11. break
      12. else:
      13. print("选项有误,请重新输入")
    2. show you the code

    2.1 while输出1-10

    1. i = 1
    2. while i <= 10:
    3. print(i, end=' ')
    4. i += 1

    2.2 水仙花数

    1. def flower_calculate(n):
    2. zxc = []
    3. while n != 0:
    4. zxc.append(n%10)
    5. n //= 10
    6. return sum(map(lambda x: x**3, zxc))
    7. i = 100
    8. while i < 1000:
    9. if i == flower_calculate(i):
    10. print(i)
    11. i += 1

    2.3 分别打印1-100的奇数和偶数

    1. zxc = [i for i in range(1, 101)]
    2. print("偶数:", zxc[1::2])
    3. print("奇数:", zxc[::2])

    2.4 求和

    1. print(sum([i if i&1 else -i for i in range(1, 100)]))

    2.5 判断闰年

    1. year = int(input("请输入年份:"))
    2. if year % 4 == 0:
    3. if year % 100 == 0:
    4. print("%d 是闰年" % year)
    5. elif year % 25 == 0:
    6. print("%d 不是闰年" % year)
    7. else:
    8. print("%d 是闰年" % year)
    9. else:
    10. print("%d 不是闰年" % year)

    2.6 猜数字

    1. import random as rd
    2. init = rd.randint(1, 100)
    3. print("现在,随机生成了一个数,这个数在[1, 100]内")
    4. while True:
    5. guess = int(input("猜猜看:"))
    6. if guess == init:
    7. print("猜对了!游戏结束")
    8. break
    9. elif guess < init:
    10. print("小了,再", end='')
    11. else:
    12. print("大了,再", end='')