示例:使用 print("Text that we do not touch\nhello\nworld") 函数,将 3 行输出到控制台:
我们不碰
hello
world的文字
您需要从命令行中删除第二行和第三行并用其他文本替换它们。它看起来像这样:
我们不接触的文本
已更改的文本 1
已更改的文本 2
示例:使用 print("Text that we do not touch\nhello\nworld") 函数,将 3 行输出到控制台:
我们不碰
hello
world的文字
您需要从命令行中删除第二行和第三行并用其他文本替换它们。它看起来像这样:
我们不接触的文本
已更改的文本 1
已更改的文本 2
我有一项任务需要所有代码都在一行上。我不会给出条件;这一切都归结为一个相当简单的表达式:
answer = a + b + c + (a ** 2 + b ** 2 + c ** 2) ** 0.5
输入数据(a、b、c)被输入到控制台,每个数字占一个新行。正如您可能已经猜到的,一行解决这个问题并不容易,因为......变量被使用两次。
这里我得出以下结论:我应该使用lambda函数并将输入数字设置为参数中的默认值:
print(lambda a=int(input()), b=int(input()), c=int(input()): a + b + c + (a ** 2 + b ** 2 + c ** 2) ** 0.5)
结论很清楚,这不是所需要的 - 将返回对函数对象的引用,因为结果,她没有被叫到。这是如何调用 lambda 函数而不将其存储在单独的变量中的问题。
PS 你不必写“;”、“eval”、“marshal”、“exec”,根据任务条款,它们是被禁止的。 PPS 输入数据:3、4、12 -> 32.0
输入示例:3 4 2 5 10 2 3 1 1 45
输出:9
a = list(map(int, input().split()))
for k in range(len(a)):
if a[k] == min(a):
x = str ((a.index(a[k+1])))
print(max(x))
请帮我理解冷流和热流的区别🥲
文档说。the code inside a flow builder does not run until the flow is collected好的,这很容易检查,因为我们可以使用创建一个流程flow { },并且内部的代码{ }在我们调用之前不会真正执行collect()。
他们在Android 文档中写道:
Unlike a cold flow built using the flow builder, a StateFlow is hot: collecting from the flow doesn't trigger any producer code. A StateFlow is always active and in memory...
我不明白,这些流的活动是什么?
StateFlow?常规流有一个 builder flow {},而它们StateFlow只是有一个函数StateFlow<T>(),其参数传递初始值。如果它只是一个函数参数,那么它是什么样的生产者代码?StateFlow is always active,但在这段测试代码中,collect()代码不会在没有调用的情况下执行,就像常规flow { }.活动可能还有其他含义,但我不明白到底是什么。fun main() = runBlocking {
val stateFlow = MutableStateFlow(0)
stateFlow.onEach {
println(it)
}.collect() // без collect() код внутри onEach не выполняется
stateFlow.emit(2)
}
请告诉我。编写了一个破译凯撒密码的程序。我不明白为什么程序会像我一样解密
answer = ''
a = ord('а')
A = ord('А')
z = ord('я')
Z = ord('Я')
for i in text:
s = ord(i)
if (s > a and s <= z) or (s > A and s <= Z):
s = s - 1
if s == a:
s = z
if s == A:
s = Z
answer += chr(s)
return answer