Buat Python Script sederhana untuk bermain batu gunting kertas permainan

Halo teman-teman, dalam tutorial ini, kita akan membuat sederhana "batu gunting kertas" permainan. Kita akan mencapai hal ini dengan membuat script Python sederhana yang hanya akan memanfaatkan Laporan Bersyarat. Jika Anda tidak memiliki pengetahuan tentang Python dan masih belum diperiksa sebelumnya kami Python Tutorial, kemudian klik di sini. Jadi sekarang, mari kita mulai topik hari ini tanpa basa-basi. Membuat Rock, Paper, Scissors permainan di Python: -Bagi Anda yang tidak tahu bagaimana Rock, Kertas, Gunting permainan bekerja atau bagaimana memainkan permainan ini, di sini adalah artikel keren di wikiHow untuk menunjukkan permainan. Baiklah, jadi sekarang mari kita mulai.

Here is the Python script: #Python script for Rock, Paper, Scissors game     print("\nPlay Rock Paper Scissors.")     while(1):         # Taking input from the user and processing it         print("Enter your choice in lower cases (rock/paper/scissor): ")         rock="rock"         paper="paper"         scissor="scissor"         human= input()         if human==rock:             human=rock             print("You chose " + rock + ".")         elif human==paper:             human=paper             print("You chose " + paper + ".")         elif human==scissor:             human=scissor             print("You chose " + scissor + ".")         else:             print("invalid choice")         # Generating Random Choices for the Computer         import random   # Importing the "Random" module in python         computer_choice=random.randint(1,3)         if computer_choice==1:             computer_choice="rock"         elif computer_choice==2:             computer_choice="paper"         elif computer_choice==3:             computer_choice="scissor"         # Comparing the choices of Computer and User and declaring winner         if computer_choice=="rock" and human=="rock":             print("Its a Tie!")         elif computer_choice=="rock" and human=="paper":             print("You won!")         elif computer_choice=="rock" and human=="scissors":             print("You lose!")         elif computer_choice=="paper" and human=="paper":             print ("Its a Tie!")         elif computer_choice=="paper" and human=="rock":             print ("You lose!")         elif computer_choice=="paper" and human=="scissor":             print ("You won!")         elif computer_choice=="scissor" and human=="paper":             print ("You lose!")         elif computer_choice=="scissor" and human=="rock":             print ("You won!")         elif computer_choice=="scissor" and human=="scissor":             print ("Its a Tie!")         elif computer_choice=="scissor" and human=="paper":             print ("You lose!")         elif computer_choice=="scissor" and human=="rock":             print ("You won!")         elif computer_choice=="scissor" and human=="scissor":             print ("Its a Tie!")         #Printing the choice of Computer         print("Computer chose " + computer_choice + ".")         # Starting the game again.         print("\n\nPlay Rock Paper Scissors again...")     # That's it! Kamu Sudah Bisa :)
Rock Paper Scissors game
You can download this Python script from Github by clicking here.

.

Previous
Next Post »