-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpythoncopy.html
More file actions
762 lines (720 loc) · 44.1 KB
/
Copy pathpythoncopy.html
File metadata and controls
762 lines (720 loc) · 44.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Python Code Lab</title>
<link rel="manifest" href="pythoncopy.webmanifest">
<link rel="icon" type="image/svg+xml"
href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%233b82f6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m10 2 6 16'/%3E%3Cpath d='m14 2-6 16'/%3E%3Cpath d='M18 12h-4'/%3E%3Cpath d='M20 9h-4'/%3E%3Cpath d='M22 6h-4'/%3E%3Cpath d='M6 15H2'/%3E%3Cpath d='M4 12H2'/%3E%3Cpath d='M2 9h2'/%3E%3C/svg%3E">
<meta name="theme-color" content="#3b82f6">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="Python Code Lab">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css"
id="prism-theme">
<link rel="stylesheet" href="pythoncopy.css">
<style id="dynamicLinksStyle">
/* Extra dynamic overrides if needed */
</style>
<script>
window.addEventListener('load', () => {
if (window.pythonCopyVersion !== 15) {
console.warn('Stale pythoncopy.js version detected. Cleaning cache and reloading...');
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().then(registrations => {
const promises = registrations.map(r => r.unregister());
Promise.all(promises).then(() => {
if ('caches' in window) {
caches.keys().then(names => {
Promise.all(names.map(name => caches.delete(name))).then(() => {
window.location.reload();
});
});
} else {
window.location.reload();
}
});
});
} else {
if ('caches' in window) {
caches.keys().then(names => {
Promise.all(names.map(name => caches.delete(name))).then(() => {
window.location.reload();
});
});
} else {
window.location.reload();
}
}
}
});
</script>
</head>
<body>
<header id="modeHeader">
<div class="brand">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round" style="color: var(--primary-color)">
<path d="m10 2 6 16" />
<path d="m14 2-6 16" />
<path d="M18 12h-4" />
<path d="M20 9h-4" />
<path d="M22 6h-4" />
<path d="M6 15H2" />
<path d="M4 12H2" />
<path d="M2 9h2" />
</svg>
Python Code Lab 4.13
<span class="mode-badge edit-badge">Edit</span>
<span class="mode-badge display-badge">Display</span>
<span class="mode-badge turtle-badge">Turtle</span>
</div>
<div class="visual-controls">
<div class="mode-toggle-pill" id="modeTogglePill">
<button class="mode-btn active" id="btnEditMode" onclick="setAppMode('edit')">Edit</button>
<button class="mode-btn" id="btnDisplayMode" onclick="setAppMode('display')">Display</button>
<button class="mode-btn" id="btnTurtleMode" onclick="setAppMode('turtle')">Turtle</button>
</div>
<div id="blocksTabHeader" style="display: none; align-items: center; gap: 12px; margin-left: auto;">
<span style="font-weight: bold; color: var(--primary-color);">Blocks Editor</span>
<input type="file" id="uploadBlocksInput" accept=".blocks,.xml" style="display: none;">
<button id="blocksUploadFileButton"
style="background: #7c3aed; color: white; font-weight: bold; padding: 6px 14px; border: none; border-radius: 20px; cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.15);">Upload
Blocks</button>
<button id="blocksDownloadFileButton"
style="background: #7c3aed; color: white; font-weight: bold; padding: 6px 14px; border: none; border-radius: 20px; cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.15);">Download
Blocks</button>
<button id="applyBlocksButton"
style="background: #10b981; color: white; font-weight: bold; padding: 6px 16px; border: none; border-radius: 20px; cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.15);">Ready
to code with text!</button>
</div>
<div class="mode-toggle-pill">
<button class="mode-btn" id="fullscreenButton" title="Full Screen"
style="font-size: 18px; padding: 2px 12px;">⛶</button>
</div>
<div class="theme-toggle" aria-label="Theme">
<label><input type="radio" id="light-mode" name="mode" value="light" checked> Light</label>
<label><input type="radio" id="dark-mode" name="mode" value="dark"> Dark</label>
</div>
<div class="font-size-control">
<label for="font-size" style="font-size: 12px;">A</label>
<input type="range" id="font-size" min="10" max="40" value="16" style="width: 100px;">
<label for="font-size" style="font-size: 16px;">A</label>
</div>
<a href="pythoncopy.html?blank" target="_blank" title="New Blank File"
style="text-decoration: none; background: none; border: none; cursor: pointer; color: var(--primary-color); display: flex; align-items: center; padding: 4px 8px; font-size: 20px; margin-left: auto;">
<img class="header-action-icon" src="images/blank.png" alt="New Blank File">
</a>
<a href="pythoncopy.html" target="_blank" title="Clean Home Screen"
style="text-decoration: none; background: none; border: none; cursor: pointer; color: var(--primary-color); display: flex; align-items: center; padding: 4px 8px; font-size: 20px;">
<img class="header-action-icon" src="images/home.png" alt="Clean Home Screen">
</a>
<a href="pythonmanual.html" target="_blank" title="Python Manual"
style="text-decoration: none; background: none; border: none; cursor: pointer; color: var(--primary-color); display: flex; align-items: center; padding: 4px 8px; font-size: 20px;">
<img class="header-action-icon" src="images/manual.png" alt="Python Manual">
</a>
</div>
</header>
<div class="instructions-panel" id="instructionsPanel">
<div style="text-align: center; margin-bottom: 24px;">
<h2>Welcome to Python Code Lab! 🐍</h2>
<p style="margin: 8px 0 0 0; font-size: 15px; line-height: 1.5;">
Write, run, and step-trace your Python code using text or visual blocks. Browse the slides below to see what you
can do!
</p>
</div>
<div class="carousel-container">
<div class="carousel-track" id="carouselTrack">
<!-- Loaded dynamically from pythoncopycarousel.html -->
</div>
</div>
</div>
<div class="starter-panel" id="starterPanel">
<div class="starter-hero">
<div>
<p class="starter-kicker">Python Code Lab 4.13</p>
<h3>Start coding</h3>
<p>Choose a blank workspace, a challenge, a course, or one of the algorithm practice sections below.</p>
</div>
<div class="quick-action-row">
<button class="starter-button action-primary" data-action="blank">Blank File</button>
<button class="starter-button action-blocks" data-action="blocks">Use Blocks</button>
<button class="starter-button action-flowchart" data-action="flowchart">Create Flowchart</button>
<button class="starter-button action-parsons" data-action="parsons">Create Parsons</button>
<button class="starter-button action-list" data-action="create-list">Create List</button>
</div>
</div>
<!-- Daily Challenge of the Day -->
<div class="daily-challenge-card" id="dailyChallengeCard">
<div class="daily-challenge-content">
<div class="daily-challenge-text">
<div class="daily-challenge-header">
<span class="daily-challenge-badge">📅 Daily Coding Quest</span>
<span id="dailyChallengeSpice">🌶️</span>
</div>
<h4 class="daily-challenge-title" id="dailyChallengeTitle">Loading today's challenge...</h4>
<p class="daily-challenge-desc" id="dailyChallengeDesc">Please wait while the challenge is prepared...</p>
<div class="daily-challenge-actions">
<a href="#" target="_blank" class="daily-challenge-btn" id="dailyChallengeBtn">
Accept Challenge ⚡
</a>
<a href="challenge_list.html" target="_blank" class="daily-challenge-view-all">
Explore All Quests
</a>
</div>
</div>
<div class="daily-challenge-image-container">
<img class="daily-challenge-image" src="challenge.png" alt="Daily Challenge Quest"
onerror="this.parentNode.style.display='none'">
</div>
</div>
</div>
<!-- Featured Courses Section -->
<p class="starter-section-title">Featured Courses</p>
<div class="courses-area" style="margin-bottom: 20px;">
<a href="worldcup_manager/index.html" class="course-button">
<img src="worldcup_manager/worldcupheroimage.jpg" alt="World Cup Dream Manager" class="course-button-image">
<div class="course-button-content">
<h4 class="course-button-title">World Cup Dream Manager 🏆</h4>
<p class="course-button-desc">Build a tournament simulation with Python logic, lists, and vector graphics!</p>
</div>
</a>
<a href="top10_python_errors_course/index.html" class="course-button">
<img src="top10_python_errors_course/Top10HeroImage.png" alt="Python Error Detectives"
class="course-button-image" style="object-fit: contain; background: #021137;">
<div class="course-button-content">
<h4 class="course-button-title">Python Error Detectives 🔍</h4>
<p class="course-button-desc">Become a code detective! Find and fix the top 10 most common errors made by
beginner Python programmers.</p>
</div>
</a>
<a href="turtle_course/index.html" class="course-button">
<img src="turtle_course/images/06_circles.png" alt="Python Turtle Graphics"
class="course-button-image" style="object-fit: cover; background: #e6f2ee;">
<div class="course-button-content">
<h4 class="course-button-title">Python Turtle Graphics 🐢</h4>
<p class="course-button-desc">Create colorful vector art while learning loops, variables, coordinates, and custom procedures!</p>
</div>
</a>
</div>
<details class="starter-section" open>
<summary>iGCSE Algorithms</summary>
<section class="igcse-lab" aria-label="iGCSE algorithm choices">
<div class="igcse-grid">
<div class="igcse-card">
<h5>Average</h5>
<div class="igcse-actions">
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/average.py">Text</button>
<button class="starter-button" data-url="blocks/igcse-average.blocks">Blocks</button>
<button class="starter-button" data-action="flowchart"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/average.py">Flowchart</button>
<button class="starter-button" data-action="parsons"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/average.py">Parsons</button>
</div>
</div>
<div class="igcse-card">
<h5>Bubble Sort</h5>
<div class="igcse-actions">
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/bubble">Text</button>
<button class="starter-button" data-url="blocks/igcse-bubble-sort.blocks">Blocks</button>
<button class="starter-button" data-action="flowchart"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/bubble">Flowchart</button>
<button class="starter-button" data-action="parsons"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/bubble">Parsons</button>
</div>
</div>
<div class="igcse-card">
<h5>Counting</h5>
<div class="igcse-actions">
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/Counting.py">Text</button>
<button class="starter-button" data-url="blocks/igcse-counting.blocks">Blocks</button>
<button class="starter-button" data-action="flowchart"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/Counting.py">Flowchart</button>
<button class="starter-button" data-action="parsons"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/Counting.py">Parsons</button>
</div>
</div>
<div class="igcse-card">
<h5>For Loop</h5>
<div class="igcse-actions">
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/540f258d395da98ce979a8a328a55ae1659c3de7/forloop.py">Text</button>
<button class="starter-button" data-url="blocks/igcse-for-loop.blocks">Blocks</button>
<button class="starter-button" data-action="flowchart"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/540f258d395da98ce979a8a328a55ae1659c3de7/forloop.py">Flowchart</button>
<button class="starter-button" data-action="parsons"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/540f258d395da98ce979a8a328a55ae1659c3de7/forloop.py">Parsons</button>
</div>
</div>
<div class="igcse-card">
<h5>If Else</h5>
<div class="igcse-actions">
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/ifelse.py">Text</button>
<button class="starter-button" data-url="blocks/igcse-if-else.blocks">Blocks</button>
<button class="starter-button" data-action="flowchart"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/ifelse.py">Flowchart</button>
<button class="starter-button" data-action="parsons"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/ifelse.py">Parsons</button>
</div>
</div>
<div class="igcse-card">
<h5>Linear Search</h5>
<div class="igcse-actions">
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/linear.py">Text</button>
<button class="starter-button" data-url="blocks/igcse-linear-search.blocks">Blocks</button>
<button class="starter-button" data-action="flowchart"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/linear.py">Flowchart</button>
<button class="starter-button" data-action="parsons"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/linear.py">Parsons</button>
</div>
</div>
<div class="igcse-card">
<h5>Maximum and Minimum</h5>
<div class="igcse-actions">
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/MaximumandMinimum.py">Text</button>
<button class="starter-button" data-url="blocks/igcse-maximum-minimum.blocks">Blocks</button>
<button class="starter-button" data-action="flowchart"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/MaximumandMinimum.py">Flowchart</button>
<button class="starter-button" data-action="parsons"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/MaximumandMinimum.py">Parsons</button>
</div>
</div>
<div class="igcse-card">
<h5>Repeat Until</h5>
<div class="igcse-actions">
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/repeat.py">Text</button>
<button class="starter-button" data-url="blocks/igcse-repeat-until.blocks">Blocks</button>
<button class="starter-button" data-action="flowchart"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/repeat.py">Flowchart</button>
<button class="starter-button" data-action="parsons"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/repeat.py">Parsons</button>
</div>
</div>
<div class="igcse-card">
<h5>Totalling</h5>
<div class="igcse-actions">
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/Totalling.py">Text</button>
<button class="starter-button" data-url="blocks/igcse-totalling.blocks">Blocks</button>
<button class="starter-button" data-action="flowchart"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/Totalling.py">Flowchart</button>
<button class="starter-button" data-action="parsons"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/Totalling.py">Parsons</button>
</div>
</div>
<div class="igcse-card">
<h5>While Loop</h5>
<div class="igcse-actions">
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/whileloop.py">Text</button>
<button class="starter-button" data-url="blocks/igcse-while-loop.blocks">Blocks</button>
<button class="starter-button" data-action="flowchart"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/whileloop.py">Flowchart</button>
<button class="starter-button" data-action="parsons"
data-url="https://gist.githubusercontent.com/jamesabela/53cc928fd03720c0803839b31bcda287/raw/635a2c7b12a1a6af75623d65d41889e8e1bbce96/whileloop.py">Parsons</button>
</div>
</div>
</div>
</section>
</details>
<details class="starter-section">
<summary>Turtle Graphics</summary>
<div class="starter-grid" style="margin-bottom: 16px;">
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/47b5a7307f549765afddc3ea046d05bc/raw/6b44d12f117fc4081f9de784b85a4882a631d65c/bubbleturtle.py">Bubble
Turtle</button>
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/47b5a7307f549765afddc3ea046d05bc/raw/d58dbb7164039c481ac8490c045e26093436d4f4/confetti.py">Confetti</button>
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/47b5a7307f549765afddc3ea046d05bc/raw/d58dbb7164039c481ac8490c045e26093436d4f4/fills.py">Fills</button>
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/47b5a7307f549765afddc3ea046d05bc/raw/d58dbb7164039c481ac8490c045e26093436d4f4/grid.py">Grid</button>
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/47b5a7307f549765afddc3ea046d05bc/raw/669f0f2f5c67b4cf992667c40c6d24f281821829/hypno.py">Hypno</button>
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/47b5a7307f549765afddc3ea046d05bc/raw/d58dbb7164039c481ac8490c045e26093436d4f4/maze.py">Maze</button>
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/47b5a7307f549765afddc3ea046d05bc/raw/d58dbb7164039c481ac8490c045e26093436d4f4/nightcity.py">Night
City</button>
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/47b5a7307f549765afddc3ea046d05bc/raw/9bedd81f6f94c6b94119e5a1422eaad88fb27c9c/spsquare.py">Spiral
Square</button>
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/47b5a7307f549765afddc3ea046d05bc/raw/9df6cf58b3e46082f2b27dc3bbf7b0f301b8dfc2/squaredfunc.py">Squared
Func</button>
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/47b5a7307f549765afddc3ea046d05bc/raw/d58dbb7164039c481ac8490c045e26093436d4f4/squarepuzzle.py">Square
Puzzle</button>
<button class="starter-button"
data-url="https://gist.githubusercontent.com/jamesabela/47b5a7307f549765afddc3ea046d05bc/raw/d58dbb7164039c481ac8490c045e26093436d4f4/steve.py">Steve</button>
</div>
</details>
<details class="starter-section">
<summary>Python Examples</summary>
<div class="starter-grid" style="margin-bottom: 16px;">
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/examples/caesar.py">Caesar
Cipher</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/examples/maze.py">Maze
Solver</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/examples/pet.py">Virtual
Pet</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/examples/rock.py">Rock Paper
Scissors</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/examples/wordle.py">Wordle</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/examples/primes.py">Primes</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/examples/file_load.py">File
Handling</button>
</div>
</details>
<details class="starter-section">
<summary>Blocks Examples</summary>
<div class="starter-grid">
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/blocks/gcse-count-occurrences.blocks">Count
Occurrences</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/blocks/gcse-find-largest.blocks">Find
Largest</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/blocks/gcse-linear-search.blocks">Linear
Search</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/blocks/gcse-random-guess.blocks">Random
Guess</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/blocks/gcse-turtle-filled-square.blocks">Turtle
Filled Square</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/blocks/greeting.blocks">Greeting</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/blocks/Letters.blocks">Letters</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/blocks/recursive-tree.blocks">Recursive
Tree</button>
<button class="starter-button"
data-url="https://raw.githubusercontent.com/jamesabela/jsfun/refs/heads/main/blocks/sierpinski.blocks">Sierpinski
Triangle</button>
</div>
</details>
</div>
<div class="workspace" id="workspace">
<div class="workspace-toolbar">
<div class="button-row">
<button class="primary-button" id="copyButton">Copy Code</button>
<button class="primary-button" id="copyForDocsButton" style="background: #8b5cf6;"
title="Copy with formatting and line numbers for Word/Google Docs">Copy for Docs</button>
<button class="primary-button" id="shareLinkButton" style="background: #10b981;"
title="Copy a shareable link that loads this code directly in Python Code Lab">Copy Link</button>
<button class="primary-button" id="createFlowchartButton" style="background: #f59e0b; display: none;"
title="Create a visual flowchart from this code (limited to 30 lines)">Create Flowchart</button>
<input type="file" id="uploadPyInput" accept=".py,.txt" style="display: none;">
<button class="primary-button" id="uploadPyButton">Upload .py</button>
<button class="primary-button" id="downloadPyButton">Download .py</button>
<button class="primary-button" id="downloadTxtButton">Download .txt</button>
<button class="primary-button" id="openNewTabButton" style="display: none;">Open in New Tab</button>
<button class="primary-button" id="makePuzzleButton" style="display: none;">Make Puzzle</button>
</div>
</div>
<section class="panel">
<div class="toggle-row">
<span id="detectionLabel" hidden>Detection: waiting for code.</span>
<div class="editor-action-row" aria-label="Editor actions">
<button type="button" class="editor-action-button" id="undoEditorButton" title="Undo last edit">Undo</button>
<button type="button" class="editor-action-button" id="redoEditorButton" title="Redo last edit">Redo</button>
<button type="button" class="editor-action-button" id="revertEditorButton"
title="Revert to the last loaded or downloaded file">Revert</button>
<button type="button" class="editor-action-button" id="playbackButton" title="Play back editing history">⏱️
Playback</button>
<span id="pasteCounter" class="paste-counter" title="Paste/upload count">0</span>
</div>
</div>
<!-- Playback Controls Bar -->
<div id="playbackControlsBar" class="playback-controls-bar"
style="display: none; flex-direction: column; gap: 10px;">
<!-- Row 1: Full-width Timeline Slider -->
<div class="playback-timeline-row" style="width: 100%;">
<div class="playback-timeline-container" id="playbackTimelineContainer" style="width: 100%;">
<div class="playback-timeline-track" id="playbackTimelineTrack">
<div id="playbackMarkersContainer" class="playback-markers-container"></div>
<input type="range" id="playbackTimeline" min="0" max="0" value="0">
</div>
</div>
</div>
<!-- Row 2: Controls, revisions label and actions -->
<div class="playback-controls-row"
style="display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; flex-wrap: wrap;">
<div style="display: flex; align-items: center; gap: 12px; flex-wrap: wrap;">
<!-- Playback buttons -->
<div class="playback-btn-group">
<button type="button" class="playback-control-btn" id="pbFirst" title="Previous checkpoint">⏮️</button>
<button type="button" class="playback-control-btn" id="pbPrev" title="Previous character">◀</button>
<button type="button" class="playback-control-btn" id="pbPlay" title="Auto Play">⏯️ Play</button>
<button type="button" class="playback-control-btn" id="pbNext" title="Next character">▶</button>
<button type="button" class="playback-control-btn" id="pbLast" title="Next checkpoint">⏭️</button>
</div>
</div>
<!-- Revisions label -->
<span id="playbackStatusLabel" class="playback-status-label"
style="flex-grow: 1; text-align: center; font-size: 13px; font-weight: 600; padding: 0 10px;">No
history</span>
<!-- Action buttons -->
<div class="playback-action-group">
<button type="button" class="playback-action-btn restore" id="pbRestore"
title="Restore this revision to editor">Restore</button>
<button type="button" class="playback-action-btn close" id="pbClose"
title="Exit playback mode">Close</button>
</div>
</div>
</div>
<!-- Blockly Workspace Area -->
<div id="blocklyArea"
style="display: none; height: 350px; position: relative; border: 1px solid #cbd5e1; border-radius: 8px; overflow: hidden; margin-bottom: 0;">
<div id="blocklyDiv" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0;"></div>
<!-- Floating Run Button within blocks area -->
<button id="blocklyRunButton"
style="position: absolute; top: 10px; right: 50px; z-index: 100; background: #10b981; color: white; border: none; padding: 8px 16px; border-radius: 20px; font-weight: bold; cursor: pointer; display: flex; align-items: center; gap: 6px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);"
title="Run Code">
Run 🚩
</button>
</div>
<!-- Split Resizer -->
<div id="editorSplitResizer"
style="display: none; height: 10px; background: #f1f5f9; cursor: ns-resize; border-top: 1px solid #cbd5e1; border-bottom: 1px solid #cbd5e1; align-items: center; justify-content: center; user-select: none;">
<div style="width: 30px; height: 4px; border-radius: 2px; background: #cbd5e1;"></div>
</div>
<div class="editor-shell" style="position: relative; background: #ffffff;" id="editorBg">
<div class="line-numbers" id="lineNumbers">1</div>
<div id="highlightLayer"
style="position: absolute; top: 14px; left: 64px; right: 0; bottom: 0; pointer-events: none; overflow: hidden; z-index: 5;">
</div>
<textarea id="editor" spellcheck="false"></textarea>
<pre id="displayEditor"><code id="displayCode" class="language-python"></code></pre>
</div>
</section>
<div class="runner-layout" id="runnerLayout">
<div class="runner-toggle" id="runnerToggle" title="Show or hide run window">◀</div>
<section class="panel runner-panel">
<div id="blocksCodePreview" class="blocks-code-preview" style="display: none;">
<div class="blocks-code-preview-header">
<span>Generated Python</span>
<div class="blocks-preview-theme-toggle" aria-label="Generated Python colors">
<label><input type="radio" id="blocksPreviewTextColors" name="blocksPreviewColors" value="text" checked>
Text</label>
<label><input type="radio" id="blocksPreviewBlockColors" name="blocksPreviewColors" value="blocks">
Blocks</label>
</div>
<button id="copyBlocksCodeButton" type="button">Copy</button>
</div>
<pre id="blocksCodePreviewText"><code id="blocksCodePreviewCode" class="language-python"></code></pre>
</div>
<p class="message" id="runnerMessage"></p>
<div class="button-row" id="teacherControlsRow">
<button class="run-button" id="runButton">Run</button>
<button class="quiz-button" id="quizButton" style="display: none;">Run Tests</button>
<button class="quiz-button" id="creativeNextButton"
style="display: none; background: #8b5cf6 !important;">Next Level ➔</button>
<button class="quiz-button" id="creativeEndButton"
style="display: none; background: #8b5cf6 !important;">Complete Course 🎓</button>
<button class="stop-button" onclick="clearRunner()">Reset</button>
</div>
<div class="button-row" id="teachControlsRow" style="display: none;">
<button class="run-button" id="playPauseButton" style="min-width: 80px;">Play</button>
<button class="primary-button" id="stepBackButton">◀ Back</button>
<button class="primary-button" id="stepButton">Step ▶</button>
<button class="stop-button" id="resetButton">Reset</button>
</div>
<!-- Turtle Canvas Panel -->
<div id="turtleCanvasContainer"
style="display: none; background: #ffffff; border: 1px solid #cbd5e1; border-radius: 8px; margin-bottom: 12px; overflow: hidden; flex-direction: column;">
<div
style="background: #f1f5f9; padding: 8px 12px; border-bottom: 1px solid #cbd5e1; display: flex; justify-content: space-between; align-items: center; font-size: 14px; font-weight: 600; color: #1e293b;"
id="turtleHeader">
<span>🐢 Turtle Graphics</span>
<button onclick="downloadCanvasImage()" class="primary-button"
style="padding: 4px 8px; font-size: 12px; background: #2563eb;">Save Image</button>
</div>
<div style="padding: 12px; display: flex; justify-content: center; background: #f8fafc;"
id="turtleCanvasWrapper">
<canvas id="turtleCanvas" width="400" height="400"
style="border: 1px solid #e2e8f0; background: #ffffff; box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); max-width: 100%; height: auto; aspect-ratio: 1;"></canvas>
</div>
</div>
<div id="displayDebuggerPanel" style="display: none;">
<!-- Tab Headers -->
<div class="display-tab-headers"
style="display: flex; gap: 4px; margin-bottom: 12px; border-radius: 8px; padding: 4px;">
<button id="tabBtnState" class="display-tab-btn active" onclick="switchDisplayTab('state')" type="button">
Variables & Call Stack
</button>
<button id="tabBtnTraceTable" class="display-tab-btn" onclick="switchDisplayTab('tracetable')"
type="button">
Trace Table
</button>
</div>
<!-- Tab Content 1: State Tracker (Call Trace & Variables) -->
<div id="tabContentState">
<div id="callTracePanel"
style="background: #e2e8f0; border-radius: 8px; padding: 10px; margin-bottom: 12px; border: 1px solid #cbd5e1;">
<h4 style="margin: 0 0 8px; font-size: 14px; color: #1e293b;">Call Trace</h4>
<div id="callTraceList"
style="font-family: Consolas, Monaco, monospace; font-size: 13px; color: #334155; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 170px; overflow-y: auto;">
</div>
</div>
<div id="variablePanel"
style="background: #e2e8f0; border-radius: 8px; padding: 10px; margin-bottom: 12px; border: 1px solid #cbd5e1;">
<h4 style="margin: 0 0 8px; font-size: 14px; color: #1e293b;">Variables</h4>
<div id="variableList"
style="font-family: Consolas, Monaco, monospace; font-size: 13px; color: #334155; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 150px; overflow-y: auto;">
</div>
</div>
</div>
<!-- Tab Content 2: Trace Table -->
<div id="tabContentTraceTable" style="display: none;">
<div id="traceTablePanel"
style="background: #e2e8f0; border-radius: 8px; padding: 10px; margin-bottom: 12px; border: 1px solid #cbd5e1;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
<h4 style="margin: 0; font-size: 14px; color: #1e293b;">Trace Table</h4>
<div style="display: flex; align-items: center; gap: 8px;">
<button id="copyTraceTableBtn" onclick="copyTraceTableToClipboard()" class="primary-button"
style="padding: 4px 8px; font-size: 11px; background: #8b5cf6; margin: 0; border-radius: 4px; font-weight: 600;">
Copy Table
</button>
</div>
</div>
<div id="traceTableContainer"
style="overflow-x: auto; max-height: 250px; border: 1px solid #cbd5e1; border-radius: 6px; background: #ffffff;">
</div>
</div>
</div>
</div>
<!-- Reference Links Panel -->
<div id="linksPanel" class="links-panel" style="display: none;">
<h4>
<span style="display: inline-flex; align-items: center; gap: 6px;">🔗 Reference Links</span>
<button id="toggleGlobalPreviewBtn"
style="padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer; border: none; transition: all 0.2s; background: #ef4444; color: white;">Preview:
Off</button>
</h4>
<div id="linksList" class="links-list">
<!-- Links populated dynamically -->
</div>
<!-- Web Preview Frame Area -->
<div id="webPreviewContainer" class="preview-container">
<div
style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px;">
<span id="previewUrlTitle" class="preview-url-title"></span>
<div style="display: flex; gap: 6px; flex-shrink: 0;">
<button id="openNewTabFromPreview" class="link-item-btn-open" style="padding: 4px 8px;">Open
External</button>
</div>
</div>
<div class="preview-iframe-wrapper">
<iframe id="webPreviewIframe" style="width: 100%; height: 100%; border: none;"
sandbox="allow-scripts allow-same-origin allow-popups allow-forms"></iframe>
<div class="preview-iframe-footer">
🛡️ If the page above appears blank, the website blocks nesting.
<a id="iframeFallbackLink" href="#" target="_blank"
style="color: var(--primary-color); font-weight: 600; text-decoration: underline;">Open in new tab</a>
</div>
</div>
</div>
</div>
<div class="console-input-panel" id="consoleInputPanel">
<p class="console-input-help" id="consoleInputHelp">This program is waiting for input.</p>
<div class="console-input-row">
<input type="text" id="consoleInputField" placeholder="Type a value and press Enter">
<button class="console-submit-button" id="consoleSubmitButton">Submit</button>
</div>
</div>
<div class="status" id="runnerStatus">Ready.</div>
<div id="output"></div>
<p class="note">
Only these modules are supported: <code>random</code>, <code>math</code>, <code>statistics</code>,
<code>datetime</code>, <code>string</code>, <code>turtle</code>, <code>time</code>. Use a local IDE for
anything else.
</p>
</section>
</div>
</div>
<script src="https://cdn.jsdelivr.net/pyodide/v0.25.0/full/pyodide.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script>
<!-- Blockly library -->
<script src="https://unpkg.com/blockly/blockly_compressed.js"></script>
<script src="https://unpkg.com/blockly/blocks_compressed.js"></script>
<script src="https://unpkg.com/blockly/python_compressed.js"></script>
<script src="https://unpkg.com/blockly/msg/en.js"></script>
<script src="https://unpkg.com/@blockly/field-colour@6.0.6/dist/index.js"></script>
<script src="https://unpkg.com/@blockly/toolbox-search@3.1.0/dist/index.js"></script>
<script src="https://unpkg.com/@blockly/plugin-workspace-search@10.1.1/dist/index.js"></script>
<script src="pythoncopyblocks.js"></script>
<script src="pythoncopy.js"></script>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('pythoncopy-sw.js')
.catch(err => console.warn('Service worker registration failed:', err));
});
}
</script>
<div class="input-container" id="inputContainer" style="text-align: center; margin-top: 40px; margin-bottom: 20px;">
<p style="font-size: 14px; margin: 0 0 8px; font-weight: 600; color: var(--primary-color);">
Advanced: Load code from a raw Gist URL or GitHub url.
</p>
<input type="text" id="urlInput" placeholder="Enter the raw URL here..." />
<button onclick="updateURL()">Load Code</button>
<p style="font-size: 13px; margin: 10px 0 0;">
<a href="python2blocks.html" target="_blank" rel="noopener">Advanced: Python to Blocks test page</a> | <a
href="https://github.com/jamesabela/jsfun/blob/main/course.md" target="_blank">Make your own course</a>
</p>
</div>
<footer>
<p>
Made with ❤️ for better thinking. If it helped you, support the project.
<a class="tea" href="https://wise.com/pay/me/jamesphilipj" target="_blank" rel="noopener">Buy me a tea</a>.
<br>
<a href="computing.html" class="computing-link">More Computing Tools</a>
</p>
<p style="margin-top:0.5rem;font-size:0.85rem;">
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener">CC BY-NC-SA 4.0</a> ©
James Abela 2024
</p>
</footer>
<script async defer src="https://scripts.simpleanalyticscdn.com/latest.js"></script>
<noscript><img src="https://queue.simpleanalyticscdn.com/noscript.gif" alt=""
referrerpolicy="no-referrer-when-downgrade" /></noscript>
<!-- File Request Modal Overlay -->
<div id="fileRequestModal" class="file-modal-overlay">
<div class="file-modal-card">
<h3 class="file-modal-title">
📁 File Required
</h3>
<p class="file-modal-body">
The Python script requires a file named <span id="fileRequestName" class="file-modal-filename">file.txt</span>
to continue running. Please select the file from your computer:
</p>
<div class="file-modal-actions">
<button id="fileRequestCancelBtn" class="file-modal-btn file-modal-btn-secondary">Cancel</button>
<button class="file-modal-btn file-modal-btn-primary">
Choose File
<input type="file" id="fileRequestInput">
</button>
</div>
</div>
</div>
</body>
</html>