用python编写程序,键盘输入一段英文,将这段英文中的单词倒序输出
时间: 2023-05-26 09:04:07 浏览: 350
``` python
sentence = input("请输入一段英文:")
words = sentence.split() # 将输入的字符串按空格分隔成单词
reversed_words = " ".join(word[::-1] for word in words) # 对每个单词进行反向处理,再用空格拼接成新的字符串
print("单词倒序输出:", reversed_words)
```
示例:
```
请输入一段英文:I love Python programming
单词倒序输出: I evol nohtyP gnimmargorp
```
相关问题
用python编写程序,用户输入一段英文,输出这段英文中所有长度为3个字母的单词
可以回答这个问题。可以使用Python中的正则表达式来匹配长度为3的单词,代码如下:
```
import re
text = input("请输入一段英文:")
words = re.findall(r'\b\w{3}\b', text)
print("这段英文中所有长度为3个字母的单词为:")
for word in words:
print(word)
```
用户输入一段英文后,程序会输出这段英文中所有长度为3个字母的单词。
用python编写程序,用户输入一段英文,然后输出这段英文中所有长度为三个字母的单词
可以使用正则表达式来匹配长度为三个字母的单词,以下是示例代码:
```python
import re
text = input("请输入一段英文:")
pattern = r'\b[a-zA-Z]{3}\b'
matches = re.findall(pattern, text)
print(matches)
```
用户输入一段英文后,程序会输出这段英文中所有长度为三个字母的单词。