Lab 6
Lab 6
Task 2: Often you play a hand cricket game, in which two players are playing if the both players out
same number of fingers it is out otherwise the score is increased by the number of fingers of the batting
player. At the end the player having more runs wins…
Now you are alone at home due to smog conditions in Lahore and want to play the game, but
not finding any friend who can play with you. NO worries, Here is the solution….
Simulate a program which takes input between 1 and 6 (inclusive), and generates a random
number between 1 and 6. If the numbers are same, than it is out, and display scores, else count the
score and move to next turn. You just interested in your batting, so do the program for one inning only.
Sample Run:
Your Choice: 3 2
Your Choice: 1 6
Your Choice: 6 2
Your Choice: 2 2
Your are out… Your score is 12.
Bonus Task: You can complete the game for the second inning as well and display the winner finally.
b. N = 3 d. N = 4
K=5 1*2*3*4*5*
12345 2**3**4**5**
12345 3***4***5***
12345 4****5****
Task 5: Assume there is a robot walking towards East. Run an infinite loop. In each iteration generate a
random value 0, 1 & 2 only. If number is 0, continue the robot in same direction, if number is 1, take
right turn, otherwise, take left turn. Print current direction of the robot:
Sample Run:
East East South East West North ...
Task 6: Assume there is a robot at point 0, 0 and currently facing towards East. Run a loop for 20 times.
In each iteration generate a random value 0, 1 & 2 only. If number is 0, continue the robot in same
direction, if number is 1, take right turn, otherwise, take left turn. In each iteration, if robot continue in
same direction, it will move one step ahead. In each iteration, print current location of the robot:
Sample Run: Draw graph paper and find next point according to the
0,0 direction
0,1
0,1
-1,1 -
2,1 -
2,1 -
...
Task 7: Assume there are two robots walking towards East at some distance to each other. Run an
infinite loop. In each iteration generate two random values (0, 1 & 2 only) to decide next direction of
both robots. Whenever robots comes in the opposite direction (i.e. East West or North South), move to
the next line and print "Assalaam-o-Alikum".
Sample Run:
North South
East East Assalaam-o-Alikum
East South
North South North West
Assalaam-o-Alikum North West
East West
Assalaam-o-Alikum