[英]Write a Python function to ask the user to input a sentence
Write a python function to ask the user to input a sentence.
写一个python函数让用户输入一个句子。 If the sentence begins with a vowel, Return the sentence as it is to be printed.
如果句子以元音开头,则按原样返回要打印的句子。 If the sentence does not begin with a vowel, Change the first letter to a capital letter and return the sentence to be printed.
如果句子不是以元音开头,则将第一个字母改为大写并返回要打印的句子。
This is what I came up with:这就是我想出的:
sentence = input("Enter a Sentence:")
vowels = ['a', 'e', 'i', 'o', 'u']
if: (sentence.find [0]=vowels)
print (sentence)
else:
(sentence[0].upper())
You have the right idea but your syntax is incorrect.您的想法是正确的,但您的语法不正确。 see below
见下文
sentence = input('Enter a Sentence:')
vowels = ['a','e','i','o','u']
if sentence[0] in vowels:
print(sentence)
else:
print(sentence.capitalize())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.