Skip to main content

Basic Python

 


Check out above post here - Instagram


Code :

import random

while True:
    choices=["rock","paper","scissors"]

    computer=random.choice(choices)

    player =None #None used to define a null value

    while player not in choices:
        player=input("Rock, Paper, or Scissors? : ").lower() #lowercase the string

    if player==computer:
        print("Computer :",computer)
        print("Player : ",player)
        print("Tie!!")
    elif player=="rock":
        if computer=="paper":
            print("Computer :",computer) #paper
            print("Player : ",player) #rock
            print("You Lose!!")

        else:
            print("Computer :",computer) #scissors
            print("Player : ",player) #rock
            print("You Win!!")

    elif player=="paper":
        if computer=="rock":
            print("Computer :",computer) #rock
            print("Player : ",player) #paper
            print("You Win!!")
        else:
            print("Computer :",computer) #scissors
            print("Player : ",player) #paper
            print("You Lose!!")
    else:
        if computer=="paper":
            print("Computer :",computer) #paper
            print("Player : ",player) #scissors
            print("You Win!!")
        else:
            print("Computer :",computer) #rock
            print("Player : ",player) #scissors
            print("You Lose!!")

    play_again=input("Play Again (yes/no): ").lower()
    if play_again!="yes": #this will break the while loop
        break

print("Game Over")


Output :



Comments

Popular posts from this blog

Draw Instagram Logo using Python Turtle👩‍💻💜

  Check out above post here -  Instagram Code from turtle import * #import all package libraries bgcolor('purple') #set background color of turtle screen as purple pencolor('white') #set color turle pen by default is black width(23) #set line thickness penup() #means pick pen up, so you can move turtle without leaving tracks #you can also use pu() goto(160,-100) #move turtle to absolute position pendown() #puts the pen down and draws as turtle moves left(90) #change the direction of the turtle at 90 degree for i in range(4):     forward(250) #move the turtle forward by the value of 250     circle(34,90) #draw a circle with a given radius and degrees as an arc penup() goto(85,30) pendown() circle(80,360) penup() goto(110,130) pendown() circle(7,360) Output

Python vs C

Instagram ID -  Sritika Manjrekar