一个。要求用户输入他们的名字。用户可以使用大写或小写字母输入名称。
如果名字以元音开头,打印消息“你的名字以元音开头。”;否则打印消息“你的名字以辅音开头。”
以大写形式打印名称的第一个字母,以及一条合适的消息。这部分应该在所有情况下执行,无论名称以元音还是辅音开头。
我做了什么:
name = input('Enter your name:')
first = name[0]
if first == 'a' or 'e' or 'i' or 'o' or 'u':
print("Your name starts with a vowel")
else first
print("Your name starts with a consonant")
print('The first letter of your name is:', name.upper[0])
请您参考如下方法:
看起来你只是有一些 python 语法错误。试试这个:
name = input('Enter your name:')
first = name[0]
if first.upper() in 'AEIOU':
print("Your name starts with a vowel")
else:
print("Your name starts with a consonant")
print('The first letter of your name is:', first.upper())
