Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

ROCK PAPER SCISSOR Game using python Language

Below 👇 is the source code for famous ROCK PAPER SCISSOR Game in Python Language.  

Just copy and paste in your Editor and you are ready to go :) 

If you have any query related to this code you are free to ask me, just put your doubt in comment section and I will try to answer it as fast as possible.☺☺

import random, sys

print("----------- Welcome to ROCK-PAPER-SCISSOR Games ------------")

wins = 0 

losses = 0 

tie = 0

while True:

    print("%s wins, %s losses, %s tie" %(wins,losses,tie))

    while True:

        print("Enter Your moves : (r)ock, (s)cissor,(p)aper or (q)uit")

        playerinput = input()

        if(playerinput =='q'):

            sys.exit()

        if playerinput == 'r' or playerinput == 's' or playerinput == 'p':

            break

        print("Type one of r,p,s or q")

        

        

        

    if playerinput == 'r':

        print("ROCK VERSUS...... ")

    elif playerinput == 'p':

        print("PAPER versus......")

    elif playerinput == 's':

        print("SCISSOR versus.....")

        

        #choice of computer starts here :

        

    randomnumber = random.randint(1,3)

    if randomnumber == 1:

        computermove = 'r'

        print("ROCK")

    elif randomnumber == 2:

        computermove = 'p'

        print("PAPER")

    elif randomnumber == 3:

        computermove = 's'

        print("SCISSOR")

        

        #count and display all movees of user and computer

        

    if playerinput == computermove:

        print("It's is a tie ")

        tie+=1

    elif playerinput == 'r' and computermove == 's':

        print("You won")

        wins+=1

    elif playerinput == 'p' and computermove == 'r':

        print("You won")

        wins+=1

    elif playerinput == 's' and computermove == 'p':

        print("You won")

        wins+=1

    else:

        losses +=1

Operator Overloading in C++

#include<iostream> using namespace std; class Complex { private: int real, imag; public: Complex(int r = 0, int i = 0){       re...