Examples
Below you can see some simple examples of different programming languages.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple HTML Example</title>
</head>
<body>
<h1>Welcome to My Simple HTML Page</h1>
<p>This is a paragraph of text. Here you can write information about your topic.</p>
<a href="https://www.google.com">Click here to go to Google</a>
</body>
</html>
JavaScript
document.addEventListener('DOMContentLoaded', () => {
const button = document.createElement('button');
button.textContent = 'Click me';
document.body.appendChild(button);
const div = document.createElement('div');
document.body.appendChild(div);
let clickCount = 0;
button.addEventListener('click', () => {
clickCount += 1;
div.textContent = `Button was clicked ${clickCount} times.`;
});
});
Python
def get_numbers_from_user():
"""Prompt the user to enter a list of numbers."""
while True:
try:
numbers = [float(x) for x in input("Please enter a list of numbers, separated by spaces: ").split()]
if numbers:
return numbers
else:
print("You didn't enter any numbers. Please try again.")
except ValueError:
print("Invalid input. Please enter a list of numbers separated by spaces.")
def calculate_average(numbers):
"""Calculate and return the average of a list of numbers."""
return sum(numbers) / len(numbers)
# Get a list of numbers from the user
numbers = get_numbers_from_user()
# Calculate the average
average = calculate_average(numbers)
# Print the average
print(f"The average of the numbers is: {average:.2f}")