Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Tugas Praktikum Big data materi ke 5

Fuad firdaus

2kb02

Npm: 22119525

Pada game batu gunting kertas Logika bot tergantung pada Random Pada index, maka dari itu saya
tambahkan index nya sehingga nilai (random.randint) Mendjadi bertambah, Semakin banyak index
semakin sulit untuk menang.

import random

input("Selamat datang di game batu, kertas, gunting! Press Enter to start.")


print()
user_wins = 0
computer_wins = 0

choices = ["batu", "kertas", "gunting" , "batu" , "batu" , "gunting" ]

while True:
random_index = random.randint(0,5)
cpu_choice = choices[random_index]

user_choice = input("batu, kertas, or gunting? ").lower()


while user_choice not in choices:
user_choice = input("Pilih yang ada aja !!: ").lower()

print()
print("Your choice:", user_choice)
print("Computer's choice:", cpu_choice)
print()

if user_choice == 'batu':
if cpu_choice == 'batu':
print("It's a tie!")
elif cpu_choice == 'gunting':
print("LU MENANG ANJAY!!!")
user_wins+=1
elif cpu_choice == 'kertas':
print("BEGO BANGET KALAH SAMA KOMPUTER!")
computer_wins+=1
elif user_choice == 'kertas':
if cpu_choice == 'kertas':
print("It's a tie!")
elif cpu_choice == 'batu':
print("LU MENANG ANJAY!!!")
user_wins+=1
elif cpu_choice == 'gunting':
print("BEGO BANGET KALAH SAMA KOMPUTER!!")
computer_wins+=1
elif user_choice == 'gunting':
if cpu_choice == 'gunting':
print("It's a tie!")
elif cpu_choice == 'kertas':
print("LU MENANG ANJAY!!!")
user_wins+=1
elif cpu_choice == 'batu':
print("BEGO BANGET KALAH SAMA KOMPUTER!!")
computer_wins+=1

print()
print("You have "+str(user_wins)+" wins")
print("The computer has "+str(computer_wins)+" wins")
print()

repeat = input("Mau main lagi ga???? (Jika iya teken huruf Y/ Jika tidak tekan huruf N) ").lower()
while repeat not in ['y', 'n']:
repeat = input("That is not a valid choice. Please try again: ").lower()

if repeat == 'n':
print("Seee uuuu")
break

print("\n----------------------------\n")

(Maka output program adalah

You might also like