Skip to content

Commit

Permalink
new learning added
Browse files Browse the repository at this point in the history
  • Loading branch information
Manjitpd committed Oct 13, 2024
1 parent a2a5fce commit 93ac732
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
15 changes: 4 additions & 11 deletions learn.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Math 4 Python - Learn</title>
<link rel="stylesheet" href="styles.css">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">

<link rel="shortcut icon" href="Untitled design1.ico" type="image/x-icon">

<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js"></script>
<script src="https://cdn.jsdelivr.net/pyodide/v0.22.1/full/pyodide.js"></script>
</head>
<body id="learn" onload="showEditor('Unititled')">
<body id="learn" onload="showEditor('Untitled')">
<div class="navbar">

<div class="nav-links">
<a href="index.html">Home</a>
<a href="learn.html" class="active">Learn</a>
Expand All @@ -27,11 +23,7 @@
<i class="fas fa-moon"></i>
</button>
</div>

<a class="logo" href="index.html"><img src="logonew.svg" height="40" width="40"></a>
<a href="learn.html" class="active">Learn</a>
<a href="challenge.html">Challenge</a>

<a class="logo" href="index.html"><img src="logonew.svg" height="40" width="40" alt="Math 4 Python Logo"></a>
</div>

<div class="content">
Expand All @@ -46,6 +38,7 @@ <h2>Python Lessons</h2>
<li><a href="#" onclick="showEditor('Conditionals')">Conditionals</a></li>
<li><a href="#" onclick="showEditor('Loops')">Loops</a></li>
<li><a href="#" onclick="showEditor('Functions')">Functions</a></li>
<li><a href="#" onclick="showEditor('Sets')">Sets</a></li> <!-- New Lesson -->
</ul>
</div>
<div class="editor-area">
Expand All @@ -65,4 +58,4 @@ <h2>Python Lessons</h2>

<script src="script.js"></script>
</body>
</html>
</html>
52 changes: 38 additions & 14 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ function showEditor(lesson) {

// Update the editor content based on the lesson chosen
if (lesson === 'Hello World') {
editor.setValue(`
editor.setValue(`\
# Lesson: Hello World in Python
# The print() function is used to display output to the console.
print("Hello, World!")`, 1); // 1 to move cursor to the end
print("Hello, World!")`, 1);
} else if (lesson === 'Variables') {
editor.setValue(`
editor.setValue(`\
# Lesson: Variables in Python
# Variables are used to store data.
x = 10 # This is an integer variable
name = "Alice" # This is a string variable
print(x, name)`, 1); // 1 to move cursor to the end
print(x, name)`, 1);
} else if (lesson === 'Conditionals') {
editor.setValue(`
editor.setValue(`\
# Lesson: Conditionals in Python
# Conditionals allow you to make decisions in your code.
x = 10
Expand All @@ -47,19 +47,45 @@ if x > 5:
else:
print("x is not greater than 5")`, 1);
} else if (lesson === 'Loops') {
editor.setValue(`
editor.setValue(`\
# Lesson: Loops in Python
# Loops allow you to repeat code multiple times.
for i in range(5):
print(f"This is iteration {i+1}")`, 1);
} else if (lesson === 'Functions') {
editor.setValue(`
editor.setValue(`\
# Lesson: Functions in Python
# Functions allow you to group code that performs a specific task.
def greet(name):
return f"Hello, {name}!"
print(greet("Alice"))`, 1);
} else if (lesson === 'Sets') { // New lesson added here
editor.setValue(`\
# Lesson: Sets in Python
# Sets are collections of unique elements.
my_set = {1, 2, 3, 4, 5}
print("Original set:", my_set)
# Adding an element
my_set.add(6)
print("After adding 6:", my_set)
# Removing an element
my_set.remove(3)
print("After removing 3:", my_set)
# Checking if an element exists
if 2 in my_set:
print("2 is in the set")
# Set operations
another_set = {4, 5, 6, 7}
union_set = my_set.union(another_set)
print("Union of sets:", union_set)
intersection_set = my_set.intersection(another_set)
print("Intersection of sets:", intersection_set)`, 1);
}
}

Expand All @@ -73,7 +99,7 @@ async function runCode() {

// Run the code using Pyodide
try {
await pyodide.runPythonAsync(`
await pyodide.runPythonAsync(`\
import sys
from io import StringIO
Expand All @@ -92,15 +118,13 @@ sys.stdout = sys.__stdout__
output = output_buffer.getvalue()
output
`).then(output => {
// console.log(output);
terminal.innerHTML += output;
});
} catch (err) {
terminal.innerHTML += `Error:\n${err}\n`;
}
}


function clearTerminal() {
document.getElementById('terminal').innerHTML = '';
}
Expand Down Expand Up @@ -137,7 +161,7 @@ function viewChallenge(challengeName) {

switch (challengeName) {
case 'Basic Math Challenge':
description.innerHTML = `
description.innerHTML = `\
<h4>Basic Math Challenge</h4>
<p>Test your skills in basic arithmetic operations. Solve the problems below:</p>
<ul>
Expand All @@ -149,7 +173,7 @@ function viewChallenge(challengeName) {
`;
break;
case 'Logic Challenge':
description.innerHTML = `
description.innerHTML = `\
<h4>Logic Challenge</h4>
<p>Use your logical thinking to solve these puzzles:</p>
<ul>
Expand All @@ -159,7 +183,7 @@ function viewChallenge(challengeName) {
`;
break;
case 'Data Structures Challenge':
description.innerHTML = `
description.innerHTML = `\
<h4>Data Structures Challenge</h4>
<p>Apply your knowledge of data structures in these coding problems:</p>
<ul>
Expand All @@ -171,4 +195,4 @@ function viewChallenge(challengeName) {
default:
description.innerHTML = `<p>Select a challenge to view its description.</p>`;
}
}
}

0 comments on commit 93ac732

Please sign in to comment.