21 game: Difference between revisions

1,845 bytes added ,  2 years ago
Added 11l
No edit summary
(Added 11l)
Line 26:
::* determine who goes first (maybe a random or user choice, or can be specified when the game begins).
<br><br>
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>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</lang>
 
{{out}}
The same as in Python.
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
1,481

edits