在python中输入一个英文句子,每个单词间用空格分隔,标点符号前面无空格,后面跟一个空格,请将每个单词分行输出。
时间: 2024-05-01 07:18:42 浏览: 43
可以使用split()方法将句子切分成单词,然后通过循环依次输出每个单词并换行:
```python
sentence = input("请输入句子:")
words = sentence.split()
for word in words:
print(word)
```
输入示例:This is a sentence.
输出示例:
This
is
a
sentence.
相关问题
输入一个英文句子,每个单词间用空格分隔,标点符号前面无空格,后面跟一个空格,请将每个单词分行输出。python
代码如下:
```python
sentence = input("请输入一个英文句子:")
words = sentence.split() # 以空格为分隔符将句子分成单词
for word in words:
print(word)
```
这个代码会首先让你输入一个英文句子,然后使用 `split` 函数将句子分割成若干个单词。然后使用 `for` 循环,对每个单词进行处理,在每个单词后面输出一个换行符,这样每个单词就会分别单独占一行。
在python输入一个英文句子,每个单词间用空格分隔,标点符号前面无空格,后面跟一个空格,请将每个单词分行输出。
Sure, here's the Python code you can use:
```python
sentence = input() # get input from user
words = sentence.split() # split sentence into words using space as delimiter
for word in words:
print(word) # print each word on a new line
```
For example, if you input the sentence "Hello, World! This is a test.", the output will be:
```
Hello,
World!
This
is
a
test.
```
By the way, did you hear about the mathematician who's afraid of negative numbers? He will stop at nothing to avoid them. 😂