|
Size: 5525
Comment:
|
Size: 5539
Comment: py3 print
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 15: | Line 15: |
| {{{ | {{{#!sagecell |
| Line 30: | Line 30: |
| print "<html><h1 align=center>Zeros</h1></html>" print "<html><h2 align=center><font color='blue'>How many zeros?</font></h2></html>" |
html("<h1 align=center>Zeros</h1>") html("<h2 align=center><font color='blue'>How many zeros?</font></h2>") |
| Line 34: | Line 34: |
| def zeros(a=("",selector(buttons=True, nrows=1, values=['Reset'] + [1..B], default=1))): | def zeros(a=selector(buttons=True, nrows=1, values=['Reset'] + [1..B], default=1)): |
| Line 37: | Line 37: |
| print "<html><center>" | html("<center>") |
| Line 41: | Line 41: |
| print "<font size=+3 color='red'>RIGHT</font>" | html("<font size=+3 color='red'>RIGHT</font>") |
| Line 54: | Line 54: |
| print "<font size=+2 color='blue'>Wrong. Try again...</font>" print "</center>" print "<font size=+%s color='#333'>"%random.randrange(-2,5) |
html("<font size=+2 color='blue'>Wrong. Try again...</font>") html("</center>") html("<font size=+%s color='#333'>"%random.randrange(-2,5)) |
| Line 58: | Line 58: |
| print "</font>" | html("</font>") |
| Line 60: | Line 60: |
| print "<br><br><center>Score: %s rounds, Average time: %.1f seconds</center>"%( round, float(tm)/round) print "</html>" |
html("<br><br><center>Score: %s rounds, Average time: %.1f seconds</center>"%( round, float(tm)/round)) |
| Line 68: | Line 67: |
| {{{ | {{{#!sagecell |
| Line 81: | Line 80: |
| queens.remove(queen) | if queen in queens: queens.remove(queen) |
| Line 97: | Line 97: |
| print 'Queen at (%d,%d) is threatened by another queen'%(x,y) | print('Queen at (%d,%d) is threatened by another queen' % (x, y)) |
| Line 101: | Line 101: |
| show(matrix_plot(board, cmap='Oranges' )) |
show(matrix_plot(board, cmap='Oranges' )) |
| Line 107: | Line 106: |
| Play nim against a perfect oponent. This interaction exemplifies the use of persistent data, and the auto_update=False option coded by mhansen and included in sage 3.3. | Play nim against a perfect opponent. This interaction exemplifies the use of persistent data, and the auto_update=False option coded by mhansen and included in sage 3.3. |
| Line 109: | Line 108: |
| {{{ | {{{#!sagecell |
| Line 134: | Line 133: |
| }}} {{{ |
|
| Line 143: | Line 141: |
| print 'You have lost' | print('You have lost') |
| Line 146: | Line 144: |
| print 'Try to take the last item' | print('Try to take the last item') |
| Line 148: | Line 146: |
| print 'Previous situation:' print game_repr(nim) |
print('Previous situation:') print(game_repr(nim)) |
| Line 152: | Line 150: |
| print 'Your move:' print game_repr(nim) |
print('Your move:') print(game_repr(nim)) |
| Line 155: | Line 153: |
| print 'You win' | print('You win') |
| Line 158: | Line 156: |
| print 'My move:' | print('My move:') |
| Line 160: | Line 158: |
| myheap,myamount=move_nim(nim) | myheap, myamount = move_nim(nim) |
| Line 163: | Line 161: |
| myheap=min(heap_number for heap_number, heap_size in enumerate(nim) if heap_size>0) | myheap=min(heap_number for heap_number, heap_size in enumerate(nim) if heap_size > 0) |
| Line 166: | Line 164: |
| print game_repr(nim) | print(game_repr(nim)) |
| Line 168: | Line 166: |
| print 'I win' | print('I win') |
| Line 170: | Line 168: |
| print 'Please move again' | print('Please move again') |
| Line 172: | Line 170: |
| print 'Choose a heap and the amount to substract from that heap' print game_repr(nim) |
print('Choose a heap and the amount to substract from that heap') print(game_repr(nim)) |
Sage Interactions - Games and Diversions
goto interact main page
Zeros
Have you ever wished you could count the number of zero digits in a long number like Rainman?
by William Stein and Sequoia Lefthand
Queens on board
An interaction to play with the problem of placing eight queens on a board so that they do not threaten each other. This interaction exemplifies the use of persistent data, and the auto_update=False option coded by mhansen and included in sage 3.3. by Pablo Angulo
Nim
Play nim against a perfect opponent. This interaction exemplifies the use of persistent data, and the auto_update=False option coded by mhansen and included in sage 3.3. by Pablo Angulo
