import random
oyuncu_skor = 0
yz_skor = 0
while True:
try:
kullanici_secimi = int(input("\nTaş: 1"
"\nKağıt: 2"
"\nMakas: 3"
"\nHangi eşyayı seçmek istiyorsanız onun sağındaki rakamı girin: "))
except NameError:
print("Sadece rakam girebilirsiniz.")
continue
except ValueError:
print("Sadece rakam girebilirsiniz.")
continue
if kullanici_secimi not in range(1, 4):
print("Geçersiz rakam, seçtiğiniz rakam 1 ve 3'ün arasında olmalı.")
continue
tkm = {1: "Taş", 2: "Kağıt", 3: "Makas"}
yz_secimi = random.randint(1,3)
print(f"\nOyuncunun seçimi: {tkm[kullanici_secimi]} | YZ'nin seçimi: {tkm[yz_secimi]}")
if kullanici_secimi == yz_secimi:
print("Berabere!")
elif (kullanici_secimi == 1) and (yz_secimi == 2):
print("YZ'nin kağıdı taşı sardı, bu roundun kazananı YZ!")
yz_skor += 1
elif (kullanici_secimi == 2) and (yz_secimi == 1):
print("Oyuncunun kağıdı YZ'nin taşı sardı, roundun kazananı oyuncu!")
oyuncu_skor += 1
elif (kullanici_secimi == 1) and (yz_secimi == 3):
print("Oyuncunun taşı YZ'nin makasını ezdi, roundun kazananı oyuncu!")
oyuncu_skor += 1
elif (kullanici_secimi == 3) and (yz_secimi == 1):
print("YZ'nin taşı oyuncunun makasını ezdi, kazanan YZ!")
yz_skor += 1
elif (kullanici_secimi == 2) and (yz_secimi == 3):
print("YZ'nin makası oyuncunun kağıdını kesti, roundun kazananı YZ!")
yz_skor += 1
elif (kullanici_secimi == 3) and (yz_secimi == 2):
print("Oyuncunun makası YZ'nin kağıdını kesti, roundun kazananı oyuncu!")
oyuncu_skor += 1
print(f"\nOyuncunun skoru: {oyuncu_skor} | YZ'nin skoru: {yz_skor}"
f"\nTaraflardan birisinin skoru 3'e ulaştığında oyun biter!")
if oyuncu_skor == 3:
print("Oyun bitti, kazanan Oyuncu!")
quit()
elif yz_skor == 3:
print("Oyun bitti, kazanan YZ!")
devam = input("Tekrar deneyip YZ'ye gününü göstermek ister misiniz? E ya da H yazın: ").lower()
if devam == "e":
continue
elif devam == "h":
quit()
else:
print("Geçersiz kelime, oyundan çıkılıyor...")
quit()
Sitedeki temel konuları bitirdiğim için, kendimi deneme amaçlı programlar yazmaya başladım. Dün yazdığım basit hesap makinesinden sonra ikinci programımı yaratmış bulunuyorum. Hatalarımı, programın eksiklerini vs. eleştirip, yorumlarınızı söylerseniz sevinirim.
def play():
import random
player_score = 0
ai_score = 0
while True:
try:
user_choice = int(input("\nRock: 1"
"\nPaper: 2"
"\nScissor: 3"
"\nWrite the number of the object you choose: "))
except NameError:
print("You can only enter number.")
continue
except ValueError:
print("You can only enter number.")
continue
if user_choice not in range(1, 4):
print("Invalid number, you have to write numbers between 1-3")
continue
rps = {1: "Rock", 2: "Paper", 3: "Scissor"}
ai_choice = random.randint(1, 3)
print(f"\nPlayer's choice: {rps[user_choice]} | AI's choice: {rps[ai_choice]}")
if user_choice == ai_choice:
print("Draw!")
elif user_choice == 1:
if ai_choice == 2:
print("AI's paper wrapped Player's rock, AI won this round!")
ai_score += 1
elif ai_choice == 3:
print("Player's rock crushed AI's scissor, Player won this round!")
player_score += 1
elif user_choice == 2:
if ai_choice == 1:
print("Players's paper wrapped AI's rock, Player won this round!")
player_score += 1
elif ai_choice == 3:
print("AI's scissor cut Player's paper, AI won this round!")
ai_score += 1
elif user_choice == 3:
if ai_choice == 1:
print("AI's rock crushed Player's scissor, AI won this round!")
ai_score += 1
elif ai_choice == 2:
print("Player's scissor cut AI's paper, Player won this round!")
player_score += 1
print(f"\nPlayer's score: {player_score} | AI's score: {ai_score}"
f"\nGame ends when player or AI's score reach 3!")
if player_score == 3:
print("Game over, Player won!")
quit()
elif ai_score == 3:
print("Game over, AI won!")
proceed = input("Wanna try again and show the AI your unmatched and great wisdom?"
"\nWrite Y or N >: ").lower()
if proceed == "y":
play()
elif proceed == "n":
quit()
else:
print("Invalid command, exiting program...")
quit()
if __name__ == "__main__":
play()