【问题标题】:I want to display words separate from a sentence我想显示与句子分开的单词
【发布时间】:2020-01-29 22:21:02
【问题描述】:

我们的老师问我们这个问题:

“从用户那里得到一个句子,然后以每行一个单词的形式显示出来。”

这很简单,但是我不能使用 .split、任何形式的列表和任何形式的循环。

【问题讨论】:

标签: python python-3.x split


【解决方案1】:
sentence = "Get a sentence from the user and display it back with one word per line."
for character in range(len(sentence)):
    if sentence[character] == ' ' or sentence[character] == '.' or sentence[character] == ',':
        print("")
    else:
        print(sentence[character], end='')

输出:

Get
a
sentence
from
the
user
and
display
it
back
with
one
word
per
line

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 2017-11-13
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多