015
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)
age = int(input())
if age < 18:
print("no drink please")
elif age < 60: # 這裡不用再判斷是否大於 18 了,因為上面已經過濾了
print("here your drink")
else:
print("you are old, please take care yourself")考拉茲猜想/冰雹猜想 (Collatz conjecture)# 考拉茲猜想/冰雹猜想 (Collatz Conjecture)
def CollatzConjecture(num: int) -> int:
while num != 1:
if num%2 == 0:
yield num
num >>= 1
elif num%2 == 1:
yield num
num *= 3; num += 1
yield num
num = int(input("Enter an integer: "))
arr = list(CollatzConjecture(num))
print(*arr)Enter an integer: 13
13 40 20 10 5 16 8 4 2 1
页:
[1]