Posts

Showing posts from June, 2021

Rock Paper and Scissor game in python

  from random import randint print ( "{:*^ 50 }" . format ( "Welcome in game" )) print () l=[ "rock" , "paper" , "scissor" ] def game(n):   s=randint( 0 , 2 )   print ( "computer chooses-" ,l[s])   if n==l[s]:     print ( "it's a tie" )     print ()   elif (n== "rock" and l[s]== "scissor" ) or \        (n== "paper" and l[s]== "rock" ) or \        (n== "scissor" and l[s]== "paper" ):      print ( "congrats you won! " )      print ()   else :     print ( "you lose it! " )     print ()     while True :   n= str ( input ( " Rock, Paper or  Scissor-" ))   if n!= "quit" :     game (n)   else :     break Example- Output- Rock, Paper or Scissor- rock computer chooses-scissor congrats you won!  Rock, Paper or Scissor-quit Game over

Guess a number game in python

 from random import randint beg=int(input("Enter a number where you want to begin")) end=int(input("Enter a number where you want to end")) def choose_num(n):   r=randint(beg,end)   if n>=beg and n<=end:     if n==r:       print("Congrats you guess it! ")       print()     else:       print("Number is",r, "try again")       print()   else:     print("Sorry number is out of range")     print() n=0 while True:   if n!=-1:      n=int(input("Guess a number"))      choose_num(n)   else:     break