鱼C论坛

 找回密码
 立即注册
查看: 2072|回复: 1

[技术交流] 015

[复制链接]
发表于 2021-8-30 20:23:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
0.缩进
1.520
2.
age = 18
isMale = True
print("抱歉,未满18岁禁止访问。") if age < 18 else print("任君选购!") if isMale else print("抱歉,本店商品可能不适合小公举哦~")
3."love" and 520 or 404
4.print(a) if a<c else c if a < b else b if b < c else c

---------------------------dds
0.
alcohol = int(input("input the amount of alcohol:"))
if alcohol < 20:
    print("no alcohol")
elif 20 <= alcohol <80:
    print("already alcohol")
elif alcohol >= 80:
    print("bad alcohol")
else:
    print("input is not right!")
1.
num = int(input("please input your number:"))
while num != 1:

1.
n = int(input("请输入一个正整数:"))

while n > 0:
    # 判断 n 是否可以被 2 整除 #
        # 按题目要求打印输出 #
        # 如果能够被 2 整除,应该写什么表达式?#
    if n%2 == 0:
        print(n,"/2 = ",n/2,sep = '')
        n /=2
    else:
        # 按题目要求打印输出 #
        # 如果不能被 2 整除,应该写什么表达式?#
        print(n,"*3+1 = ",n*3+1,sep = '')
        n = n*3+1
    if n == 1:
        break
**************************************
4.
print(a) if a < c else print(c) if a < b else print(b) if b < c else print(c)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-9-8 12:40:41 | 显示全部楼层
  1. age = int(input())
  2. if age < 18:
  3.     print("no drink please")
  4. elif age < 60: # 這裡不用再判斷是否大於 18 了,因為上面已經過濾了
  5.     print("here your drink")
  6. else:
  7.     print("you are old, please take care yourself")
复制代码
考拉茲猜想/冰雹猜想 (Collatz conjecture)
  1. # 考拉茲猜想/冰雹猜想 (Collatz Conjecture)
  2. def CollatzConjecture(num: int) -> int:
  3.     while num != 1:
  4.         if num%2 == 0:
  5.             yield num
  6.             num >>= 1
  7.         elif num%2 == 1:
  8.             yield num
  9.             num *= 3; num += 1
  10.     yield num

  11. num = int(input("Enter an integer: "))
  12. arr = list(CollatzConjecture(num))
  13. print(*arr)
复制代码
  1. Enter an integer: 13
  2. 13 40 20 10 5 16 8 4 2 1
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-18 22:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表