Created
May 3, 2020 16:11
-
-
Save bringsik100/40a13c19dc66599d343456e1be8199f5 to your computer and use it in GitHub Desktop.
permainan tebak angka sederhana dari 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 randint as ri | |
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\n | |
PERMAINAN TEBAK ANGKA 1 S/D 9 | |
\n\n""") | |
kesempatan = 0 | |
jawaban = ri(1,10) | |
while kesempatan < 3: | |
tebakan = int(input('\nmasukkan angka dari 1 sampai 9\n')) | |
kesempatan += 1 | |
if kesempatan == 3: | |
print("\nKESEMPATAN HABIS!\n") | |
return lagi() | |
else: | |
try: | |
if tebakan > jawaban: | |
print(f'SALAH! (tebakan) terlalu besar') | |
continue | |
elif tebakan < jawaban: | |
print(f'SALAH! (tebakan) terlalu kecil') | |
continue | |
else: | |
print('SELAMAT ANDA TEBAKAN ANDA BENAR!') | |
return lagi() | |
except Exception: | |
print("SALAH! yang anda masukkan bukan angka") | |
return lagi() | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment