我有一个代码可以将单词变成猪拉丁语,我从一个函数中获取用户输入。我需要放入
print(convert_word(n))
使用用户输入进行打印?
def void(n):
n = input("Enter the word you want converted to Pig Latin: ")
return n
VOWELS = ('a', 'e', 'i', 'o', 'u')
# Function definition
def convert_word(word):
# Assign the first letter of word to variable first_letter
first_letter = word[0]
# Check if the word starts with a vowel
if first_letter in VOWELS:
# If it is a vowel, then keep the word as it is and add "hay" to the end
return word + "hay"
# If the word does not start with a vowel
else:
# Returns the word except word[0] and add "ay" at the end of the string
return word[1:] + word[0] + "ay"
# Prompt the user to enter the input string
# Call the function to convert the word to pigLatin
print(convert_word(n))
答案 0 :(得分:0)
由于void()
仅调用input()
,因此您可以完全取消该功能,而只需像这样调用convert_word()
:
print(convert_word(input('some prompt >')))
如果由于某些原因您确实需要void()
函数,
print(convert_word(void()))
如果愿意,您可以更改void()
的声明以删除输入参数,因为它从未使用过。