"Output the numbers from 1-9 with a While loop\n",
"\n"
]
...
...
@@ -29,13 +27,58 @@
"id": "4963b926",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "5e94ba89",
"metadata": {},
"source": [
"i = 0\n",
"while i < 9:\n",
" i += 1\n",
" print(i)"
"Write a function that uses a while loop to calculate the sum of numbers from 1 to n, where n is input by the user."
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "6d7d3a25",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n"
]
}
],
"source": []
},
{
"cell_type": "markdown",
"id": "8a698b41",
"metadata": {},
"source": [
"### 1.1.2 for loop\n",
"\n",
"Write a function that calculates the sum of all numbers in a list provided by the user."
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "2ccbb033",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"137\n"
]
}
],
"source": []
},
{
"cell_type": "markdown",
"id": "ba627a5b",
...
...
@@ -65,40 +108,51 @@
]
}
],
"source": []
},
{
"cell_type": "markdown",
"id": "0f5a3313",
"metadata": {},
"source": [
"squares = [x**2 for x in range(0,101)]\n",
"print(squares)\n",
"\n",
"x = 0\n",
"ndivisable = [y for y in range(0,1001) if ((y % 11 != 0) and (y % 13 != 0))]\n",
"print(ndivisable)\n",
"### 1.3 Input output\n",
"\n",
"Ask the user for their first name, last name, and age.\n",
"\n",
"evenodd = [0 if (z % 2 !=0) else 1 for z in range(0,101)]\n",
"print(evenodd)\n"
"Calculates the year they were born based on the current year (2024).\n",
"\n",
"Print a message like: \"Hello [first name] [last name], you are [age] years old and were born in [year]\"."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b0d6532a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "750b8da3",
"metadata": {},
"source": [
"# Aufgabe: Temperatur-Kategorisierung und Empfehlungen\n",
"# 1.4 Task: Temperature categorization and recommendations\n",
"\n",
"Schreibe ein Python-Programm, das die aktuelle Temperatur in Grad Celsius als Eingabe akzeptiert und anhand dieser verschiedene Aktionen durchführt.\n",
"Write a Python program that accepts the current temperature in degrees Celsius as input and performs various actions based on this.\n",
"\n",
"## Anforderungen\n",
"### input\n",
"Ask the user to enter the current temperature (in degrees Celsius).\n",
"\n",
"### 1. Eingabe\n",
"Fordere den Benutzer auf, die aktuelle Temperatur (in Grad Celsius) einzugeben.\n",
"### 2. categories and actions\n",
"- Temperature < 0**: Indicate that it is very cold and recommend wearing a thick coat and gloves.\n",
"- **0 ≤ temperature < 10**: State that it is cold and recommend wearing a jacket and scarf.\n",
"- **Temperature ≥ 30**: State that it is very hot and recommend drinking plenty of water and using sunscreen.\n",
"\n",
"### 2. Kategorien und Aktionen\n",
"- **Temperatur < 0**: Gib aus, dass es sehr kalt ist, und empfehle, einen dicken Mantel und Handschuhe zu tragen.\n",
"- **0 ≤ Temperatur < 10**: Gib aus, dass es kalt ist, und empfehle, eine Jacke und einen Schal zu tragen.\n",
"- **Temperatur ≥ 30**: Gib aus, dass es sehr heiß ist, und empfehle, viel Wasser zu trinken und Sonnenschutz zu verwenden.\n",
"\n",
"### 3. Ungültige Eingaben\n",
"Falls der Benutzer etwas anderes als eine Zahl eingibt, soll das Programm eine Fehlermeldung ausgeben und den Benutzer bitten, eine gültige Zahl einzugeben.\n",
"die exception kann mit try und except ValueError: programmiert werden\n"
"### 3. invalid entries (advanced)\n",
"If the user enters something other than a number, the program should display an error message and ask the user to enter a valid number. <br>\n",
"The exception can be programmed with try and except ValueError:.\n"
]
},
{
...
...
@@ -115,201 +169,184 @@
]
}
],
"source": []
},
{
"cell_type": "markdown",
"id": "4e8fa130",
"metadata": {},
"source": [
"def temperatur_kategorisierung():\n",
" while True:\n",
" try:\n",
" # Eingabe der aktuellen Temperatur\n",
" temperatur = float(input(\"Bitte die aktuelle Temperatur in Grad Celsius eingeben: \"))\n",
"## 1.5 Check Tic Tac Toe\n",
"\n",
"The goal of this task is to check whether someone has WON a game of Tic Tac Toe.\n",
"\n",
" # Kategorien und Aktionen\n",
" if temperatur < 0:\n",
" print(\"Es ist sehr kalt. Empfehlung: Tragen Sie einen dicken Mantel und Handschuhe.\")\n",
" elif 0 <= temperatur < 10:\n",
" print(\"Es ist kalt. Empfehlung: Tragen Sie eine Jacke und einen Schal.\")\n",
" elif temperatur >= 30:\n",
" print(\"Es ist sehr heiss. Empfehlung: Trinken Sie viel Wasser und verwenden Sie Sonnenschutz.\")\n",
" else:\n",
" print(\"Das Wetter ist angenehm. Keine besonderen Empfehlungen.\")\n",
" break # Beende die Schleife nach erfolgreicher Eingabe\n",
" except ValueError:\n",
" print(\"Ungültige Eingabe. Bitte geben Sie eine gültige Zahl ein.\")\n",
"Program a function ```check_tictactoe(game)``` which returns whether player 1 or player 2 has won\n",
"\n",
"# Programm starten\n",
"temperatur_kategorisierung()"
"**hint:** several lines can be checked for a winner when using a for loop\n",
"Write a Python program for a number-guessing game. The program should allow the user to attempt guessing a secret number up to 5 times. If the user guesses the correct number, the program should display a success message and stop. If the user fails to guess correctly within 5 attempts, it should display the correct number and a failure message.\n",
"\n",
"The range of the Random number should be between 1 and 25"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "c176ee1b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Try to guess the number between 1 and 25. You have 5 attempts.\n",
"Invalid input. Please enter a valid number.\n",
"None\n"
]
}
],
"source": []
},
{
"cell_type": "markdown",
"id": "3cd42cc9",
"id": "b6a24fe8",
"metadata": {},
"source": [
"## Task: Manage a Material Inventory System with pandas\n",
"## 1.7 Pandas\n",
"\n",
"Create a Python program to manage an inventory of materials using nested dictionaries.\n",
"Pokémon data analysis (again)\n",
"\n",
"The Following features should be implemented \n",
"\n",
"- **View Inventory:** Display all categories, materials, and their details.\n",
"- **Add a New Material:** Add a new material to a category (create a new category if it doesn't exist).\n",
"- **Update Material** Quantity: Modify the quantity of an existing material by adding or subtracting a given amount. Ensure the total cannot go below 0.\n",
"- **Delete a Material:** Remove a material from the inventory entirely.\n",
"- **Exit:** End the program.\n"
"1. load data:\n",
"Load the data set into a Pandas DataFrame.\n",
"\n",
"2. basic analysis:\n",
" - How many Pokémon are there in total in the data set?\n",
" - How many different Pokémon types are there (including type 1 and type 2)? (**hint** use the ```unique()``` method to find all unique pokemons)(use the ```concat()``` method to concatenate the calues from multiple Series into a single serie)\n",
" List all unique types.\n",
"3. filtering and grouping:\n",
" - Find the strongest Pokémon (highest total value).\n",
" - Find the fastest Pokémon (highest speed value).\n",
" - Create a ranking list of the 5 legendary Pokémon with the highest total value.\n",
"4. visualisation:\n",
" - Create a bar chart showing the average values (total) of the Pokémon per generation."
Ask the user for their first name, last name, and age.
Calculates the year they were born based on the current year (2024).
Print a message like: "Hello [first name] [last name], you are [age] years old and were born in [year]".
%% Cell type:code id:b0d6532a tags:
``` python
```
# Aufgabe: Temperatur-Kategorisierung und Empfehlungen
%% Cell type:markdown id:750b8da3 tags:
Schreibe ein Python-Programm, das die aktuelle Temperatur in Grad Celsius als Eingabe akzeptiert und anhand dieser verschiedene Aktionen durchführt.
# 1.4 Task: Temperature categorization and recommendations
## Anforderungen
Write a Python program that accepts the current temperature in degrees Celsius as input and performs various actions based on this.
### 1. Eingabe
Fordere den Benutzer auf, die aktuelle Temperatur (in Grad Celsius) einzugeben.
### input
Ask the user to enter the current temperature (in degrees Celsius).
### 2. Kategorien und Aktionen
-**Temperatur < 0**: Gib aus, dass es sehr kalt ist, und empfehle, einen dicken Mantel und Handschuhe zu tragen.
-**0 ≤ Temperatur < 10**: Gib aus, dass es kalt ist, und empfehle, eine Jacke und einen Schal zu tragen.
-**Temperatur ≥ 30**: Gib aus, dass es sehr heiß ist, und empfehle, viel Wasser zu trinken und Sonnenschutz zu verwenden.
### 2. categories and actions
- Temperature < 0**: Indicate that it is very cold and recommend wearing a thick coat and gloves.
- **0 ≤ temperature < 10**: State that it is cold and recommend wearing a jacket and scarf.
- **Temperature ≥ 30**: State that it is very hot and recommend drinking plenty of water and using sunscreen.
### 3. Ungültige Eingaben
Falls der Benutzer etwas anderes als eine Zahl eingibt, soll das Programmeine Fehlermeldung ausgeben und den Benutzer bitten, eine gültige Zahl einzugeben.
die exception kann mit try und except ValueError: programmiert werden
### 3. invalid entries (advanced)
If the user enters something other than a number, the program should display an error message and ask the user to enter a valid number. <br>
The exception can be programmed with try and except ValueError:.
%% Cell type:code id:f7746781 tags:
``` python
deftemperatur_kategorisierung():
whileTrue:
try:
# Eingabe der aktuellen Temperatur
temperatur=float(input("Bitte die aktuelle Temperatur in Grad Celsius eingeben: "))
# Kategorien und Aktionen
iftemperatur<0:
print("Es ist sehr kalt. Empfehlung: Tragen Sie einen dicken Mantel und Handschuhe.")
elif0<=temperatur<10:
print("Es ist kalt. Empfehlung: Tragen Sie eine Jacke und einen Schal.")
eliftemperatur>=30:
print("Es ist sehr heiss. Empfehlung: Trinken Sie viel Wasser und verwenden Sie Sonnenschutz.")
else:
print("Das Wetter ist angenehm. Keine besonderen Empfehlungen.")
break# Beende die Schleife nach erfolgreicher Eingabe
exceptValueError:
print("Ungültige Eingabe. Bitte geben Sie eine gültige Zahl ein.")
# Programm starten
temperatur_kategorisierung()
```
%% Output
Das Wetter ist angenehm. Keine besonderen Empfehlungen.
%% Cell type:markdown id:3cd42cc9 tags:
%% Cell type:markdown id:4e8fa130 tags:
## 1.5 Check Tic Tac Toe
## Task: Manage a Material Inventory System with pandas
The goal of this task is to check whether someone has WON a game of Tic Tac Toe.
Create a Python program to manage an inventory of materials using nested dictionaries.
Program a function ```check_tictactoe(game)``` which returns whether player 1 or player 2 has won
The Following features should be implemented
**hint:** several lines can be checked for a winner when using a for loop
-**View Inventory:** Display all categories, materials, and their details.
-**Add a New Material:** Add a new material to a category (create a new category if it doesn't exist).
-**Update Material** Quantity: Modify the quantity of an existing material by adding or subtracting a given amount. Ensure the total cannot go below 0.
-**Delete a Material:** Remove a material from the inventory entirely.
Write a Python program for a number-guessing game. The program should allow the user to attempt guessing a secret number up to 5 times. If the user guesses the correct number, the program should display a success message and stop. If the user fails to guess correctly within 5 attempts, it should display the correct number and a failure message.
The range of the Random number should be between 1 and 25
%% Cell type:code id:c176ee1b tags:
``` python
```
%% Output
Try to guess the number between 1 and 25. You have 5 attempts.
Invalid input. Please enter a valid number.
None
%% Cell type:markdown id:b6a24fe8 tags:
## 1.7 Pandas
Pokémon data analysis (again)
1. load data:
Load the data set into a Pandas DataFrame.
2. basic analysis:
- How many Pokémon are there in total in the data set?
- How many different Pokémon types are there (including type 1 and type 2)? (**hint** use the ```unique()``` method to find all unique pokemons)(use the ```concat()``` method to concatenate the calues from multiple Series into a single serie)
List all unique types.
3. filtering and grouping:
- Find the strongest Pokémon (highest total value).
- Find the fastest Pokémon (highest speed value).
- Create a ranking list of the 5 legendary Pokémon with the highest total value.
4. visualisation:
- Create a bar chart showing the average values (total) of the Pokémon per generation.