Created
May 3, 2020 16:38
-
-
Save bringsik100/e0bcc899519221f451527cc30467b515 to your computer and use it in GitHub Desktop.
permainan gunting batu kertas sederhana dengan python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import choice as rc | |
opsi = {'q':'batu','w':'gunting','e':'kertas'} | |
kalah = [['batu','kertas'],['kertas','gunting'],['gunting','batu']] | |
menang = [['kertas','batu'],['gunting','kertas'],['batu','gunting']] | |
imbang = [['batu','batu'],['gunting','gunting'],['kertas','kertas']] | |
def lagi(): | |
print('main lagi ?\njawab Y untuk ya \n') | |
main_lagi = input("\t : ") | |
if main_lagi.lower() == 'y': | |
return main() | |
else: | |
print('\nTERIMA KASIH') | |
pass | |
def main(): | |
print("""\n | |
PERMAINAN BATU GUNTING KERTAS | |
PILIH | |
Q untuk BATU | |
W untuk GUNTING | |
E untuk KERTAS | |
\n""") | |
def gunbaker(): | |
while True: | |
com = rc(list(opsi.values())) | |
kamu = input('pilihanmu : ') | |
try: | |
pilihan = [opsi[kamu],com] | |
if pilihan in kalah: | |
print(f'kamu memilih {opsi[kamu]} dan komputer memilih {com}, KAMU KALAH \n') | |
continue | |
elif pilihan in menang: | |
print(f'kamu memilih {opsi[kamu]} dan komputer memilih {com}, KAMU MENANG \n') | |
return lagi() | |
elif pilihan in imbang: | |
print(f'kamu memilih {opsi[kamu]} dan komputer memilih {com}, IMBANG \n') | |
continue | |
except Exception: | |
print('pilihanmu tidak dikenali, coba lagi \n') | |
return gunbaker() | |
gunbaker() | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment