Skip to content

Commit

Permalink
Merge pull request #31 from Manjitpd/new-manjit
Browse files Browse the repository at this point in the history
new learning added
  • Loading branch information
codingkatty authored Oct 13, 2024
2 parents bb78f83 + e22358a commit 6c19e45
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
13 changes: 5 additions & 8 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 @@ -28,10 +24,10 @@
</button>
</div>

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

<!-- <a href="learn.html" class="active">Learn</a>
<a href="challenge.html">Challenge</a> -->

</div>

<div class="content">
Expand All @@ -46,6 +42,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 +62,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 @@ -139,7 +163,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 @@ -151,7 +175,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 @@ -161,7 +185,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 @@ -173,4 +197,4 @@ function viewChallenge(challengeName) {
default:
description.innerHTML = `<p>Select a challenge to view its description.</p>`;
}
}
}

0 comments on commit 6c19e45

Please sign in to comment.