Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
62
Task/21-game/11l/21-game.11l
Normal file
62
Task/21-game/11l/21-game.11l
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
F select_count(game_count)
|
||||
‘selects a random number if the game_count is less than 18. otherwise chooses the winning number’
|
||||
Int t
|
||||
I game_count < 18
|
||||
t = random:(1..3)
|
||||
E
|
||||
t = 21 - game_count
|
||||
print(‘The computer chooses #.’.format(t))
|
||||
R t
|
||||
|
||||
F request_count()
|
||||
‘request user input between 1,2 and 3. It will continue till either quit(q) or one of those numbers is requested.’
|
||||
V t = ‘’
|
||||
L
|
||||
X.try
|
||||
t = input(‘Your choice 1 to 3 :’)
|
||||
I Int(t) C [1, 2, 3]
|
||||
R Int(t)
|
||||
E
|
||||
print(‘Out of range, try again’)
|
||||
X.catch
|
||||
I t == ‘q’
|
||||
R 0
|
||||
E
|
||||
print(‘Invalid Entry, try again’)
|
||||
|
||||
F start()
|
||||
V game_count = 0
|
||||
print("Enter q to quit at any time.\nThe computer will choose first.\nRunning total is now #.".format(game_count))
|
||||
V roundno = 1
|
||||
L
|
||||
print("\nROUND #.: \n".format(roundno))
|
||||
V t = select_count(game_count)
|
||||
game_count = game_count + t
|
||||
print("Running total is now #.\n".format(game_count))
|
||||
I game_count >= 21
|
||||
print(‘So, commiserations, the computer has won!’)
|
||||
R 0
|
||||
t = request_count()
|
||||
I t == 0
|
||||
print(‘OK,quitting the game’)
|
||||
R -1
|
||||
game_count = game_count + t
|
||||
print("Running total is now #.\n".format(game_count))
|
||||
I game_count >= 21
|
||||
print(‘So, congratulations, you've won!’)
|
||||
R 1
|
||||
roundno++
|
||||
|
||||
V c = 0
|
||||
V m = 0
|
||||
L
|
||||
V o = start()
|
||||
I o == -1
|
||||
L.break
|
||||
E
|
||||
c += I o == 0 {1} E 0
|
||||
m += I o == 1 {1} E 0
|
||||
print(‘Computer wins #. game, human wins #. games’.format(c, m))
|
||||
V t = input(‘Another game?(press y to continue):’)
|
||||
I t != ‘y’
|
||||
L.break
|
||||
Loading…
Add table
Add a link
Reference in a new issue