我正在为最后一个项目编写代码,这是一个允许用户设计自己车牌的应用程序。你知道吗
我想写一些代码,基本上允许用户输入一个英语单词(长度小于或等于10个字符),然后应用程序问他是否要删除单词中的特定元音,然后应用程序输出最后的单词。你知道吗
因为我是一个初学者,我只知道如何编写代码,将省略所有元音在任何用户输入。你觉得怎么样?你知道吗
到目前为止我尝试的代码:
keepOrDeleteVowel1 = input("Would you like to delete the vowels? Type 'yes' to delete vowels, or 'no' to type a new word.")
if keepOrDeleteVowel1 == "no" or "No" or "NO":
print("This is your word: " + original + "." + " Enjoy your new license plate! Thank you for using this app.")
break
elif keepOrDeleteVowel1 == "yes" or "Yes" or "YES":
firstLetter = original[0]
lastLetter = original[len(original)]
if firstLetter != "A" or firstLetter != "E" or firstLetter != "I" or firstLetter != "O" or firstLetter != "U" \
or lastLetter != "A" or lastLetter != "E" or lastLetter != "I" or lastLetter != "O" or lastLetter != "U":
original =original.remove("A")
original =original.remove("E")
original =original.remove("I")
original =original.remove("O")
original =original.remove("U")
print (original)
抱歉格式化了。上面的代码应该可以删除所有元音,但只有在单词没有以元音开头或结尾的情况下。但是我想改变这一点,允许用户自己删除元音,而不是让程序删除所有元音。你知道吗
请详细回复,非常感谢。你知道吗
输出:
您可以通过
input()
向用户请求元音,方法与向用户请求原始单词的方法相同。当你保存到一个变量,你可以检查,以确保他们已经输入了元音,如果这样,你可以继续并删除它,如我下面所示。为了避免在比较时用小写和大写输入每个元音,我用lower()
将它们的输入转换成小写,您也可以对“no”这样做。你知道吗相关问题 更多 >
编程相关推荐