Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python大小写匹配输入和输出_Python_String - Fatal编程技术网

Python大小写匹配输入和输出

Python大小写匹配输入和输出,python,string,Python,String,我正在做一个关于猪的拉丁语问题,我相信这里的每个人都熟悉这个问题。唯一我似乎无法得到的是匹配输入和输出的大小写。例如,当用户输入拉丁语时,“我的代码”生成atinLay。我想让它产生Atinlay import string punct = string.punctuation punct += ' ' vowel = 'aeiouyAEIOUY' consonant = 'bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ' final_word = inpu

我正在做一个关于猪的拉丁语问题,我相信这里的每个人都熟悉这个问题。唯一我似乎无法得到的是匹配输入和输出的大小写。例如,当用户输入拉丁语时,“我的代码”生成
atinLay
。我想让它产生
Atinlay

import string

punct = string.punctuation
punct += ' '
vowel = 'aeiouyAEIOUY'
consonant = 'bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ'

final_word = input("Please enter a single word. ")
first_letter = final_word[:1]

index = 0

if any((p in punct) for p in final_word):
    print("You did not enter a single word!")
else:
    while index < len(final_word) and (not final_word[index] in vowel):
        index = index+1
    if any((f in vowel) for f in first_letter):
        print(final_word + 'yay')
    elif index < len(final_word):
        print(final_word[index:]+final_word[:index]+'ay')
导入字符串
点=字符串。标点符号
点状+=''
元音='aeiouyeiouy'
辅音='bcdfghjklmnpqrstvwxzbcdfhjklmnpqrstvwxz'
final_word=输入(“请输入一个单词”)
第一个字母=最后一个单词[:1]
索引=0
如果有((点号中的p)表示最后一个单词中的p):
打印(“您没有输入任何单词!”)
其他:
而index
只需使用内置的字符串函数即可

s = "Hello".lower()
s == "hello"
s = "hello".upper()
s == "HELLO"
s = "elloHay".title()
s == "Ellohay"
你需要的是。完成piglatin转换后,可以使用
title()
内置函数生成所需的输出,如下所示:

>>> "atinLay".title()
'Atinlay'

要检查字符串是否为小写,可以使用。浏览一下文档。

或“hello world”.title()=Hello World好了,更好了。谢谢,我忘了提到如果用户输入全小写,那么输出应该保持小写。示例Latin->Atinlay Latin->atinlayThank,我忘了提到如果用户输入全小写,那么我不希望输出大写。@ChristopherFlach这很简单。只需使用str.islower(),它也是内置的。