top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Rock Paper and Scissor

Writer's picture: Sabin PantaSabin Panta

From an early age, we have been playing Rock Paper, and scissors with our friends mostly either in a duel or to make a group in a football match. Sometimes, a losing one has to be a keeper(Sadly, I lost most of the time).


import random game=['R','P','S'] computer_action=random.choice(game) print(computer_action) user_action=input("Rock Paper Scissor(R/P/S):").upper() if user_action == computer_action: print(f"Both players selected {user_action}. It's a tie!") elif user_action == "R": if computer_action == "S": print("Rock smashes scissors! You win!") else: print("Paper covers rock! You lose.") elif user_action == "P": if computer_action == "R": print("Paper covers rock! You win!") else: print("Scissors cuts paper! You lose.") elif user_action == "S": if computer_action == "P": print("Scissors cuts paper! You win!") else: print("Rock smashes scissors! You lose.")

The code is as simple as it looks. First, we have to import random modules in Python which allow us to choose randomly from our given choice(here it's either Paper, Rock, or Scissor as defined by the list "game"). The input function allows users to enter the value. ".upper()" changes the string value in upper case given the value is in lower case to allow for the later conditional procedure. The loops are quite easy to figure out. If the user enters Paper, there is only one way he could win and one way he could lose as shown in the conditional statement. Thus the coding task is solved. Congratulation on creating your first game.

0 comments

Recent Posts

See All

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page