Created
May 12, 2021 05:57
-
-
Save EliezerDev/52473f9d6845ed63a5ab6ff192850b09 to your computer and use it in GitHub Desktop.
Game Tebak Angka
This file contains 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
# Jangan lupa install third - party package "colored" dan "pyfiglet" | |
# pip install colored pyfiglet | |
# third-party package | |
from colored import fore, style | |
from pyfiglet import figlet_format | |
# built-in package | |
from random import randint | |
from os import system | |
percobaan = 1; | |
limit = 3 | |
angka_rand = randint(1, 10) | |
print(figlet_format("Tebak Angka")) | |
while percobaan <= limit: | |
# tunjukan percobaan ke - x pada user | |
print(f"{fore.MAGENTA}===== Percobaan ke - {percobaan} ===== {style.RESET}") | |
# tangkap user input | |
input_user = int(input(f"{fore.BLUE}Tebak Angka 1 - 10: {style.RESET}")) | |
# cek jawaban / input dari user | |
if(input_user == angka_rand): | |
# system('cls') | |
print(f"{fore.GREEN}{figlet_format('Kamu Menang !')}{style.RESET}") | |
break | |
# beri petunjul ke user | |
if input_user < angka_rand: | |
print(f"{fore.YELLOW}Angka terlalu KECIL{style.RESET}") | |
elif input_user > angka_rand: | |
print(f"{fore.YELLOW}Angka terlalu BESAR{style.RESET}") | |
# cek jika user kalah | |
if percobaan == limit: | |
# system('cls') | |
print(f"{fore.RED}{figlet_format('Kamu Kalah !')}{style.RESET}") | |
percobaan += 1 | |
print('\n') | |
# created by Eliezer Dev | |
# Youtube channel: Eliezer Dev | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment