Posts

Showing posts from January, 2022

problem no 76:21 stick problem

  Question : lets say you have 21 sticks.There is a competion in between you and your computer.yours will be first turn.you can pick maximum 4 sticks .after your turn computer will pick some sticks.THE ONE WHO PICKS UP THE 21ST STICK WILL BE THE LOOSER.        Now your task is to write the program in python in such a way that computer will not loose at any cost.     Answer:The following program written in python  is in favour of computer.This program always  makes computer win.   stick= 21 rem_stick= 21 while stick!= 1 : print( "its your turn" ) print( "note that you cannot pick more than 4 sticks" ) p=int(input()) z= 5 -p print( "its my turn" ) print( "i will pick" ,z, "sticks" ) rem_stick=rem_stick-( 5 ) print( "only" ,rem_stick, "remaining now" ) if (rem_stick== 1 ): break ; print( "only one stick is remaining" ) print( "youre a looser ,i won" )