简体   繁体   English

写一个Python函数让用户输入一个句子

[英]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.

相关问题 如何要求用户在python 3中输入函数 - How to ask a user to input a function in python 3 如何要求用户提供布尔输入以限定if语句并使用Python中的该信息打印句子 - How to ask for a boolean input from a user to qualify if statements and print a sentence using that information in Python 如何使用 python 在主 Function 上向用户询问 function 输入? - How to ask User for function input on Main Function with python? 递归函数在具有错误处理的Python中要求用户输入 - Recursive function to ask for user input in Python with error handling 如何使用 Python 类并要求用户输入? - How to use a Python class and ask for user input? Python要求用户输入没有换行符? - Python ask for user input without a newline? 如果python中有错误,请让用户重新输入输入 - ask user to reenter input if there is an error in python Python:如何使用输入函数在句子中间(填空式)获取用户输入? - Python: How do I get user input in the middle of a sentence (fill-in-the-blank style) using the input function? 写一个 python function 反转一个用点分隔的句子 - Write a python function to reverse a sentence that are separated by dot 在Python中,如何要求用户输入列表,然后能够在函数中使用任何数据类型来使用它 - In Python, how to ask for user to input a list, and then to be able to work with it, whatever data type, in a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM