输入一个英文句子,每个单词间用空格分隔,标点符号前面无空格,后面跟一个空格,请将每个单词分行输出。python
时间: 2023-06-09 22:04:42 浏览: 741
代码如下:
```python
sentence = input("请输入一个英文句子:")
words = sentence.split() # 以空格为分隔符将句子分成单词
for word in words:
print(word)
```
这个代码会首先让你输入一个英文句子,然后使用 `split` 函数将句子分割成若干个单词。然后使用 `for` 循环,对每个单词进行处理,在每个单词后面输出一个换行符,这样每个单词就会分别单独占一行。
相关问题
输入一个英文句子,每个单词间用空格分隔,标点符号前面无空格,后面跟一个空格,请将每个单词分行输出。
Sure, I can answer that. Here's the solution to your question:
```
sentence = input("Please enter an English sentence: ")
words = sentence.split()
for word in words:
print(word)
```
This code will prompt the user to input an English sentence, split the sentence into individual words, and then print each word on a new line. Let me know if you have any other questions!
Python输入一个英文句子,每个单词间用空格分隔,标点符号前面无空格,后面跟一个空格,请按顺序将每个单词分行输出(标点符号归属与前面的单词
好的,这是一个简单的Python程序,可以实现您的要求:
```python
sentence = input("请输入一个英文句子:")
words = sentence.split()
for word in words:
if word[-1] in [".", ",", "!", "?", ";", ":"]:
print(word[:-1])
print(word[-1])
else:
print(word)
```
您可以将英文句子输入到程序中,程序将把句子分割成单词,并按照要求输出每个单词。如果单词的最后一个字符是标点符号,则将标点符号和单词分别输出。
阅读全文