المتطلبات الأساسية — الحلول
حل التمرين 1
mkdir -p /tmp/my-portfolio
cd /tmp/my-portfolio
touch README.md about.md projects.md
git init
محتوى README.md:
# Alice Johnson
I'm learning to build AI-powered applications.
## Skills
- Python
- JavaScript
- Git
- Flask
## Connect
[GitHub](https://github.com/alicejohnson)
git add README.md
git commit -m "Initial commit"
echo "About me page" > about.md
git add about.md
git commit -m "Add about page"
حل التمرين 2
# counter.py
import sys
def count_file(filename):
with open(filename, 'r') as f:
content = f.read()
lines = content.split('\n')
words = content.split()
chars = len(content)
return len(lines), len(words), chars
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python counter.py <filename>")
sys.exit(1)
filename = sys.argv[1]
lines, words, chars = count_file(filename)
print(f"File: {filename}")
print(f"{'Lines:':<10}{lines:>6}")
print(f"{'Words:':<10}{words:>6}")
print(f"{'Chars:':<10}{chars:>6}")
اختبره:
echo -e "Hello world\nThis is a test\nPython is fun" > sample.txt
python counter.py sample.txt
حل التمرين 3
// weather.ts
interface Todo {
userId: number;
id: number;
title: string;
completed: boolean;
}
interface Weather {
city: string;
temperature: number;
condition: string;
}
async function fetchWeather(): Promise<void> {
const response = await fetch("https://jsonplaceholder.typicode.com/todos/1");
const todo: Todo = await response.json();
const weather: Weather = {
city: "Sample City",
temperature: 22,
condition: todo.title
};
console.log(`City: ${weather.city}, Temperature: ${weather.temperature}°C, Condition: ${weather.condition}`);
}
fetchWeather().catch(console.error);
حل التمرين 4
mkdir -p /tmp/git-flow && cd /tmp/git-flow
git init
# الفرع الرئيسي
echo 'print("Hello")' > main.py
git add main.py && git commit -m "Add hello script"
# فرع الميزة
git checkout -b feature/greet
cat > main.py << 'EOF'
name = input("Enter your name: ")
print(f"Hello, {name}!")
EOF
git add main.py && git commit -m "Add greeting feature"
# الدمج مرة أخرى
git checkout main
git merge feature/greet
git branch -d feature/greet
git log --oneline
حل التمرين 5
data.py:
import json
import random
names = ["Alice", "Bob", "Charlie", "Diana", "Eve"]
cities = ["NYC", "London", "Tokyo", "Paris", "Sydney"]
people = []
for i in range(100):
person = {
"name": random.choice(names),
"age": random.randint(10, 80),
"city": random.choice(cities)
}
people.append(person)
with open("people.json", "w") as f:
json.dump(people, f, indent=2)
print("Generated 100 people")
report.ts:
import * as fs from 'fs';
interface Person {
name: string;
age: number;
city: string;
}
const data = fs.readFileSync('people.json', 'utf-8');
const people: Person[] = JSON.parse(data);
const adults = people.filter(p => p.age > 18);
let markdown = "# Adults Report\n\n";
markdown += "| Name | Age | City |\n";
markdown += "|------|-----|------|\n";
adults.forEach(p => {
markdown += `| ${p.name} | ${p.age} | ${p.city} |\n`;
});
fs.writeFileSync('adults.md', markdown);
console.log(`Wrote ${adults.length} adults to adults.md`);
# شغّله
python data.py
tsx report.ts
git init
git add .
git commit -m "Generate people data and adult report"
git log --oneline
git diff HEAD~1
حل التمرين 6
find . -name "*.py" -print | xargs wc -l | tail -1 > loc.txt
حل التمرين 7
# Spaghetti Carbonara
## Ingredients
- 200g spaghetti
- 2 eggs
- 100g pancetta
- 50g Parmesan cheese
- Salt and pepper
## Instructions
1. Boil spaghetti in salted water.
2. Fry pancetta until crispy.
3. Beat eggs with grated Parmesan.
4. Drain pasta and mix with pancetta.
5. Remove from heat and stir in egg mixture.
6. Season with pepper and serve.
> **Tip:** Don't let the eggs scramble — the heat of the pasta is enough to cook them.
Cooking time: 15 minutes