我已经完成了代码挑战,其中之一是编写了一行代码,打印出先前的结果(我已经完成了)
print(str(year)*int(number))
但它也表示在每个返回值之间放置一个换行符。 因此,例如var'year'返回一个int值,并且该int被打印出 次数取决于用户输入的内容。
我只是不知道'\ n'在这行代码中的位置。
print(str(year)*int(number))
答案 0 :(得分:1)
您可以在print
的各个参数之间打印一个分隔符,该分隔符将出现在它们之间而不是空格
print('a', 'b', sep='\n')
我们可以使用参数解压缩为number
提供print
多个参数,并用'\n'
分隔它们
year = 2000
number = 5
print(*[year]*number, sep='\n')
打印
2000
2000
2000
2000
2000
答案 1 :(得分:1)
您可以使用一个简单的循环:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task
':android:packageRelease'.
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.gradle.tooling.BuildException: Failed to read key
shaperecognisingreleasekey from store
"C:\Users\Albrecht\Documents\Apps\ShapeRecognisingGame\android\release\android-release.apk":
Invalid keystore format
at com.android.build.gradle.internal.scope.BuildElements$ExecutorBasedScheduler$transform$2.invoke(BuildElements.kt:133)
at com.android.build.gradle.internal.scope.BuildElements$ExecutorBasedScheduler$transform$2.invoke(BuildElements.kt:110)
at kotlin.sequences.SequencesKt___SequencesKt$onEach$1.invoke(_Sequences.kt:1260)
at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:149)
at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:109)
at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:133)
at kotlin.sequences.TransformingSequence$iterator$1.hasNext(Sequences.kt:153)
at kotlin.sequences.SequencesKt___SequencesKt.toCollection(_Sequences.kt:633)
at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(_Sequences.kt:663)
at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:654)
at com.android.build.gradle.internal.scope.BuildElements$ExecutorBasedScheduler.transform(BuildElements.kt:140)
at com.android.build.gradle.internal.scope.BuildElements$ExecutorBasedScheduler.into(BuildElements.kt:115)
at com.android.build.gradle.internal.scope.BuildElementActionScheduler.into(BuildElementActionScheduler.kt:32)
at com.android.build.gradle.tasks.PackageAndroidArtifact.doFullTaskAction(PackageAndroidArtifact.java:393)
at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)
Caused by: com.android.ide.common.signing.KeytoolException: Failed to
read key shaperecognisingreleasekey from store
"C:\Users\Albrecht\Documents\Apps\ShapeRecognisingGame\android\release\android-release.apk":
Invalid keystore format
at com.android.ide.common.signing.KeystoreHelper.getCertificateInfo(KeystoreHelper.java:212)
at com.android.build.gradle.internal.packaging.IncrementalPackagerBuilder.withSigning(IncrementalPackagerBuilder.java:161)
at com.android.build.gradle.tasks.PackageAndroidArtifact.doTask(PackageAndroidArtifact.java:646)
at com.android.build.gradle.tasks.PackageAndroidArtifact.splitFullAction(PackageAndroidArtifact.java:496)
at com.android.build.gradle.tasks.PackageAndroidArtifact.lambda$doFullTaskAction$2(PackageAndroidArtifact.java:388)
at com.android.build.gradle.internal.scope.BuildElements$ExecutorBasedScheduler$transform$$inlined$forEach$lambda$1.call(BuildElements.kt:121)
at com.android.build.gradle.internal.scope.BuildElements$ExecutorBasedScheduler$transform$$inlined$forEach$lambda$1.call(BuildElements.kt:110)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinTask.externalAwaitDone(ForkJoinTask.java:326)
at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:391)
at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:719)
at com.android.ide.common.internal.WaitableExecutor.waitForAllTasks(WaitableExecutor.java:215)
at com.android.build.gradle.internal.scope.BuildElements$ExecutorBasedScheduler.transform(BuildElements.kt:125)
Caused by: java.io.IOException: Invalid keystore format
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:658)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:56)
at sun.security.provider.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:224)
at sun.security.provider.JavaKeyStore$DualFormatJKS.engineLoad(JavaKeyStore.java:70)
at java.security.KeyStore.load(KeyStore.java:1445)
at com.android.ide.common.signing.KeystoreHelper.getCertificateInfo(KeystoreHelper.java:190)
默认情况下,这将插入for _ in range(number):
print(year)
-因为每次打印都是单独的命令,并且默认的\n
参数适用于打印。
Patrick Haugh用打印命令参数end=\n
击败了我50秒,该参数使您可以指定要在打印值之间放置的内容:
sep
这会在每个数字之间打印换行符-默认情况下,它会打印一个空格。
您可以将收集到的数字放在列表中,将列表分解为其元素,然后使用\ n分隔符进行打印:
print(1,2,3,4,sep="\n")
更多信息可以在
中找到