我该如何为它编写代码 [英] How do I write code for it

查看:81
本文介绍了我该如何为它编写代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入将包含偶数行的文本。输入将以空行终止。假设有2n行输入。你的程序应该输出输入的最后n行,即输入的后半部分,然后是前n行,即输入的前半部分。



例如,如果输入如下:



亲爱的朋友,



let's吃$



然后输出应该是:



让我们吃



亲爱的朋友,



我尝试过:



i = 1

而1:

line = input()

如果行=='':

The input will consist of an even number of lines of text. The input will be terminated by a blank line. Suppose there are 2n lines of input. Your program should print out the last n lines of the input, i.e., the second half of the input, followed by the first n lines, i.e., the first half of the input.

E.g., if the input is the following:

our dear friend,

let's eat

then the output should be:

let's eat

our dear friend,

What I have tried:

i = 1
while 1:
line = input()
if line=='':

推荐答案

再次阅读你的作业问题。

你需要阅读文本行,并存储它们,直到你得到空行来结束输入。

之后,您需要有两个循环来打印输出:首先打印最后N / 2行,然后打印前N / 2行。



如果您考虑使用它,这并不复杂ttle,并尝试分阶段完成:让输入部分先工作,然后开始处理输出。

但这是你的功课,所以我不会给你代码!
Read your homework question again.
You need to read in lines of text, and store them until you get the blank line to end the input.
After that, you need to have two loops to print that output back: first print the last N / 2 lines, then print the first N / 2 lines.

This isn't complicated if you think about it for a little, and try to do it in stages: get the input part working first, then start working on the output.
But it's your homework, so I'll give you no code!


这篇关于我该如何为它编写代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆