Posts

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,...

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

List comprehension hackerrank solution in python

Image
  Let's learn about list comprehensions! You are given three integers     and     representing the dimensions of a cuboid along with an integer   . Print a list of all possible coordinates given by     on a 3D grid where the sum of     is not equal to   . Here,   . Please use list comprehensions rather than multiple loops, as a learning exercise. Example All permutations of   are: . Print an array of the elements that do not sum to  . Input Format Four integers   and  , each on a separate line. Constraints Print the list in lexicographic increasing order. Sample Input 0 1 1 1 2 Sample Output 0 [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]] Explanation 0 Each variable   and   will have values of   or  . All permutations of lists in the form  . Remove all arrays that sum to   to leave only the valid permutations. Sample Input 1 2 2 2 ...