Untitled

 avatar
unknown
plain_text
2 years ago
1.4 kB
2
Indexable
import random

# Define a list of city names in Turkish
sehirler = ["İstanbul", "Ankara", "İzmir", "Bursa", "Adana", "Antalya", "Konya", "Gaziantep", "Kocaeli", "Balıkesir", "Samsun", "Trabzon", "Eskişehir", "Malatya", "Kayseri", "Denizli"]

# Define a function to generate a random city name from the list
def rastgele_sehir():
    return random.choice(sehirler)

# Define a function to display a city name with only 2 letters visible
def gizli_sehir(sehir):
    # Convert the city name to upper case
    sehir = sehir.upper()
    # Choose 2 random indices from the range of the length of the city name
    gizli = random.sample(range(len(sehir)), 2)
    # Convert the rest of the characters to underscores
    gizli_sehir = "".join([sehir[i] if i in gizli else "_" for i in range(len(sehir))])
    return gizli_sehir

# Main program loop
while True:
    # Generate a random city name
    sehir = rastgele_sehir()
    # Display the city name with only 2 letters visible
    gizli = gizli_sehir(sehir)
    print("Bir şehir ismi bulun. Sadece 2 harf görüntüleniyor:")
    print(gizli)
    # Get the user's guess and convert it to upper case
    tahmin = input("Tahmininiz: ").upper()
    # Check if the guess matches the original city name
    if tahmin == sehir:
        print("Tebrikler, doğru cevap!")
        break
    else:
        print("Maalesef yanlış cevap. Doğru cevap: " + sehir)