Python'da büyük küçük harf duyarlılığı kaldırma

nrhlns

Zeptopat
Katılım
29 Nisan 2022
Mesajlar
2
Daha fazla  
Cinsiyet
Kadın
Merhaba, Sezar Şifreleme komutu oluşturdum pythonda fakat texte büyük harfle girdiğimde çalışmıyor. Kod aşağıda yardımcı olabilir misiniz?

Kod:
def main():

    Encryption= "e"

    Decryption="d"

    print("please select the operation 'e'for encryption,")

    print( " 'd' for decryption")

    choice=input("Encryption / Decryption ")

  

    text=input("write your plain text: ")

  

    shift=int(input("write your shift amount: "))

  

    if choice=="e" or choice=="E":

        encrypted(text,shift)

    elif choice=="d" or choice=="D":

        decrypted(text,shift)

    else:

        print("Error! Invalid choice")

        choice=input("enter your choice: ")

      

def encrypted(text,shift):

    encrypted_text = ''

 

    alphabet = [

        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',

        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'

    ]

    for i in text:

 

        if i not in alphabet:

            encrypted_text += i

          

        else:

            encrypted_text += alphabet[

                (alphabet.index(i)+shift) % len(alphabet)]

 

    print("Chiper Text:", encrypted_text)



    return main()







def decrypted(text,shift):

    decrypted_text = ''

 

    alphabet = [

        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',

        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'

    ]

    for i in text:

 

        if i not in alphabet:

            decrypted_text += i

        else:

            decrypted_text += alphabet[

                (alphabet.index(i)-shift) % len(alphabet)]

 

    print("Chiper Text:", decrypted_text)

    return main()



main()
 
Kodunuza bakmakla uğraşmayacağım. Her 2 satır arasına 500 satır boşluklu şekilde paylaşmazsanız bakabilirim.

Ek olarak; Python'da main öyle tanımlanmaz.

Bu yüzden bir örnek paylaşacağım. İstediğin şekilde elma yaz, fark etmez. Her türlü küçültmüş oluyorsun.
Kod:
a = input("elma yaz: ").lower()

if a == "elma":
    print("afaram")
else:
    print("elma dedik")
 
Son düzenleme:

Yeni konular

Geri
Yukarı