Skip to content

Commit 9d32d5d

Browse files
Initialising gh-pages branch
0 parents  commit 9d32d5d

File tree

322 files changed

+70482
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

322 files changed

+70482
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.quarto/
2+
/*/.jupyter_cache/
3+
/*/__pycache__

.nojekyll

Whitespace-only changes.

404.qmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Page Not Found
3+
---
4+
5+
Sorry, the page you requested cannot be found (perhaps it was moved or renamed).
6+
7+
You may want to try searching to find the page's new location.

LICENSE

Lines changed: 429 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Introduction to Python
2+
3+
This repository contains course materials for a "Programming with Python" course first teached at Kühne Logistics University Hamburg in Fall 2024. Most of it is written with Quarto and the corresponding website is hosted as Github page under [beyondsimulations.github.io/python-course/](https://beyondsimulations.github.io/python-course/).
4+
5+
## Quick Overview
6+
7+
This module introduces programming with Python over the course of 13 weeks. It is aimed at beginners with no prior programming experience. The course is based on many examples that illustrate how to tackle potentially complex issues and implement solutions.
8+
9+
### Course Structure
10+
11+
The course is structured into three main parts:
12+
13+
1. **Part I: Introduction to Programming with Python**
14+
- Basic concepts, syntax, data types, control structures, functions, and object classes
15+
16+
2. **Part II: Data Science with Python**
17+
- Data manipulation, descriptive and explorative analysis, visualization
18+
19+
3. **Part III: Programming Projects**
20+
- Application of knowledge in group projects
21+
22+
For more detailed information about the course structure, lectures, and content, please refer to the [syllabus](general/syllabus.qmd).
23+
24+
## Contact
25+
26+
If you have any questions regarding the course, please contact:
27+
28+
[[email protected]](mailto:[email protected]?subject=Programming%20with%20Python%20-%20KLU24%3A%20%3CYour%20subject%3E)
29+
30+
## Contributors
31+
32+
Thanks to [Phillip Bach](https://github.com/PhilippBach) whose original course material laid the foundation for this course.

_quarto.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
project:
2+
type: website
3+
output-dir: docs
4+
5+
render:
6+
- 404.qmd
7+
- index.qmd
8+
- general/*.qmd
9+
- part-01/*.qmd
10+
- part-02/*.qmd
11+
- part-03/*.qmd
12+
- part-04/*.qmd
13+
- part-05/*.qmd
14+
- part-06/*.qmd
15+
- part-07/*.qmd
16+
- part-10/*.qmd
17+
- assignments/*.qmd
18+
19+
website:
20+
title: "Programming with Python"
21+
repo-url: https://github.com/beyondsimulations/Introduction-to-Python
22+
site-url: https://beyondsimulations.github.io/Introduction-to-Python
23+
repo-actions: [edit, source, issue]
24+
bread-crumbs: true
25+
reader-mode: true
26+
sidebar:
27+
style: floating
28+
collapse-level: 1
29+
search: true
30+
contents:
31+
- text: "Welcome"
32+
href: index.qmd
33+
- text: "Syllabus"
34+
href: general/syllabus.qmd
35+
- text: "***"
36+
- section: "01 Introduction "
37+
contents:
38+
- text: "Lecture"
39+
href: part-01/lecture-introduction.qmd
40+
- text: "Tutorial"
41+
href: part-01/tutorial-introduction.qmd
42+
- section: "02 Control Flow"
43+
contents:
44+
- text: "Lecture"
45+
href: part-02/lecture-control.qmd
46+
- text: "Tutorial"
47+
href: part-02/tutorial-control.qmd
48+
- section: "03 Functions"
49+
contents:
50+
- text: "Lecture"
51+
href: part-03/lecture-functions.qmd
52+
- text: "Tutorial"
53+
href: part-03/tutorial-functions.qmd
54+
- section: "04 Dimensions"
55+
contents:
56+
- text: "Lecture"
57+
href: part-04/lecture-dimensions.qmd
58+
- text: "Tutorial"
59+
href: part-04/tutorial-dimensions.qmd
60+
- section: "05 Errors"
61+
contents:
62+
- text: "Lecture"
63+
href: part-05/lecture-errors.qmd
64+
- text: "Tutorial"
65+
href: part-05/tutorial-errors.qmd
66+
- section: "06 Modules"
67+
contents:
68+
- text: "Lecture"
69+
href: part-06/lecture-modules.qmd
70+
- text: "Tutorial"
71+
href: part-06/tutorial-modules.qmd
72+
- section: "07 Scientific Computing"
73+
contents:
74+
- text: "Lecture"
75+
href: part-07/lecture-scientific.qmd
76+
- text: "Tutorial"
77+
href: part-07/tutorial-scientific.qmd
78+
- section: "10 Projects"
79+
contents:
80+
- text: "Lecture"
81+
href: part-10/lecture-projects.qmd
82+
- text: "***"
83+
- section: "Assignments"
84+
contents:
85+
- text: "01 Assignment"
86+
href: assignments/assignment-1.qmd
87+
- text: "02 Assignment"
88+
href: assignments/assignment-2.qmd
89+
- text: "FAQs"
90+
href: general/faq.qmd
91+
- text: "Literature"
92+
href: general/literature.qmd
93+
page-footer:
94+
center: "Programming with Python, Tobias Vlćek</br>CC BY-NC-SA 4.0"
95+
right:
96+
- icon: github
97+
href: https://github.com/beyondsimulations/Introduction-to-Python
98+
- icon: linkedin
99+
href: https://linkedin.com/in/tobiasvlcek
100+
101+
format:
102+
html:
103+
theme: litera
104+
css: styles.css
105+
toc: true
106+
pdf:
107+
include-in-header:
108+
text: |
109+
\usepackage{fvextra}
110+
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}}
111+
112+
execute:
113+
cache: true
114+
115+

assignments/assignment-1.qmd

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: "Assignment I"
3+
subtitle: "Programming with Python"
4+
5+
format:
6+
html:
7+
theme: litera
8+
highlight-style: arrow
9+
code-overflow: wrap
10+
linkcolor: "#a60000"
11+
code-copy: true
12+
code-link: true
13+
toc: true
14+
toc-location: right
15+
pdf:
16+
documentclass: report
17+
geometry:
18+
- margin=1in
19+
fontfamily: roboto
20+
fontfamilyoptions: sfdefault
21+
colorlinks: true
22+
---
23+
24+
# Introduction
25+
This is the first of the two assignments for this course. It will be graded as pass/fail and you and your group of up to 3 students will need to submit it before the start of the last lecture. Please hand in one assignment per group via the e-mail address [[email protected]](mailto:[email protected]).
26+
27+
In the assignment, you will practice the concepts you learned in the first part of the course. You will find a lot of information online and you are welcome to use generative AI to help you with the assignment. However, you are not allowed to copy the code from other groups and you have to indicate where and how you used AI to help you. Try to use comments to structure and to explain your code. Furthermore, use descriptive variable names and format your code nicely in order to make it more readable.
28+
29+
# Tax refund for donations
30+
In this excercise, you will create a program that is able to calculate the amount of tax a person can get back for a donation. First, research the rules for tax refunds for donations in Germany. Then, create a program that is able to **calculate the amount of tax a person can get back** for a donation. The program should ask the user for the **amount of the donation and the yearly income** and then calculate the amount of tax the user can get back. The program should then print the amount of tax to the console. Note, that the program should also handle wrong inputs from the user, e.g. if the user enters a negative donation amount or a non-numeric income.
31+
32+
```{python}
33+
# Tax refund for donations
34+
# TODO: Create a program that is able to calculate the amount of tax a person can get back for a donation.
35+
# Your code here
36+
```
37+
38+
:::{.callout-tip}
39+
Use the `input()` function to get user input in order to let the user interact with your program.
40+
:::
41+
42+
# Text based adventure game
43+
In this excercise, you will create a text based adventure game. You are completely free in the choice of the story, but it must **at least include 3 choices, 2 different endings and the choice to restart the game**. Try to use the concepts of conditionals, loops, and functions to create a game that is both fun and interactive for the user. Note, that the program should also handle wrong inputs from the user, e.g. if the user enters a choice that is not available.
44+
45+
```{python}
46+
# Test based adventure game
47+
# TODO: Create a text based adventure game with at least 3 choices, 2 different endings and the choice to restart the game.
48+
# Your code here
49+
```
50+
51+
# Hangman
52+
In this excercise, you will create a program that is able to play the game Hangman. The program should ask the **game master for a secret word**. Afterward, it should ask the player to guess a letter and then check if the letter is in the word. The program should then print the word with the guessed letters and the number of tries left. The program should also handle wrong inputs from the user, e.g. if the user enters a non-letter or a letter that is already guessed.
53+
54+
```{python}
55+
# Hangman
56+
# TODO: Create a program that is able to play the game Hangman with a game master and one player.
57+
# Your code here
58+
```
59+

assignments/assignment-2.qmd

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: "Assignment II"
3+
subtitle: "Programming with Python"
4+
5+
format:
6+
html:
7+
theme: litera
8+
highlight-style: arrow
9+
linkcolor: "#a60000"
10+
code-copy: true
11+
code-link: true
12+
toc: true
13+
toc-location: right
14+
code-overflow: wrap
15+
pdf:
16+
documentclass: report
17+
geometry:
18+
- margin=1in
19+
fontfamily: roboto
20+
fontfamilyoptions: sfdefault
21+
colorlinks: true
22+
---
23+
24+
# Introduction
25+
This is the second of the two assignments for this course. It will be graded as pass/fail and you and your group of up to 3 students will need to submit it before the start of the last lecture. Please hand in one assignment per group via the e-mail address [[email protected]](mailto:[email protected]).
26+
27+
In the assignment, you will practice the concepts you learned in the second part of the course. You will find a lot of information online and you are welcome to use generative AI to help you with the assignment. However, you are not allowed to copy the code from other groups and you have to indicate where and how you used AI to help you. Try to use comments to structure and to explain your code. Furthermore, use descriptive variable names and format your code nicely in order to make it more readable.
28+
29+
# Redact secret information
30+
In this excercise, you will create a program that is able to redact secret information in a text. The program should be able to redact the following: **zip codes, names, email addresses and phone numbers.** The program should ask the user **for a filename** and then read the file and **redact the secret information**. The program should then print the redacted text to the console and write it to a new file called `redacted.txt`. You can find a file with secret information in the git repository under `assignments/secret-text.txt`.
31+
32+
```{python}
33+
# Secret information redactor
34+
# TODO: Create a program that is able to redact secret information in a text.
35+
# Your code here
36+
```
37+
38+
# Dice roll simulator
39+
In this excercise, you will create a program that is able to simulate dice rolls and visualizes their distribution. The program should ask the user for **the number of sides on the dice and the number of dices to roll**. Then, the program should simulate the dice rolls 10000 times and **visualize the distribution** of the dice rolls using a histogram.
40+
41+
```{python}
42+
# Dice roll simulator
43+
# TODO: Create a program that is able to simulate a dice roll.
44+
# Your code here
45+
```
46+
47+
# Regression analysis
48+
In this excercise, you will create a program that performs linear regression on a dataset with housing prices. The dataset can be found in the git repository under `assignments/hamburg_housing_prices.csv`. The dataset contains the following columns:
49+
50+
- Price: The price of the house in Euros.
51+
- Area: The area of the house in square meters.
52+
- Rooms: The number of rooms in the house.
53+
- Year_Built: The year the house was built.
54+
- Distance_to_Center: The distance to the center of Hamburg in kilometers.
55+
56+
Your task is to perform a **linear regression analysis** on the dataset and to predict the price of a house based on its area, number of rooms, year it was built and its distance to the center of Hamburg. You can use the `pandas` library to read the dataset and the `numpy` library to perform the linear regression analysis. After performing the linear regression analysis, use the `matplotlib` library to visualize the relationship between the price and the other features as well as the predicted prices for a given set of features.
57+
58+
```{python}
59+
# Regression analysis
60+
# TODO: Create a program that performs linear regression analysis on the dataset.
61+
# Your code here
62+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import pandas as pd
2+
import numpy as np
3+
from datetime import datetime, timedelta
4+
5+
# Set random seed for reproducibility
6+
np.random.seed(42)
7+
8+
# Generate data
9+
n_samples = 1000
10+
data = {
11+
'Price': np.random.lognormal(mean=12.5, sigma=0.4, size=n_samples) * 1000, # Price in Euros
12+
'Area': np.random.lognormal(mean=4.5, sigma=0.3, size=n_samples),
13+
'Rooms': np.random.randint(1, 6, n_samples),
14+
'Year_Built': np.random.randint(1900, 2023, n_samples),
15+
'Distance_to_Center': np.random.lognormal(mean=1.5, sigma=0.5, size=n_samples)
16+
}
17+
18+
# Create DataFrame
19+
df = pd.DataFrame(data)
20+
21+
# Adjust prices based on factors
22+
df['Price'] *= np.sqrt(df['Area']) / 10
23+
df['Price'] *= (df['Rooms'] ** 0.2)
24+
df['Price'] *= (1 - (2023 - df['Year_Built']) * 0.005) # Slight decrease for older buildings
25+
df['Price'] *= (1 - df['Distance_to_Center'] * 0.015) # Slight decrease for properties farther from center
26+
df['Price'] /= 300
27+
28+
# Round and adjust data types
29+
df['Price'] = df['Price'].round(-3) # Round to nearest thousand
30+
df['Area'] = df['Area'].round().astype(int)
31+
df['Distance_to_Center'] = df['Distance_to_Center'].round(1)
32+
33+
# Add some missing values
34+
df.loc[np.random.choice(df.index, 50), 'Year_Built'] = np.nan
35+
df.loc[np.random.choice(df.index, 50), 'Distance_to_Center'] = np.nan
36+
37+
# Save to CSV
38+
df.to_csv('assignments/hamburg_housing_prices.csv', index=False)
39+
print("Dataset created and saved as 'hamburg_housing_prices.csv'")
40+
41+
# Display first few rows and data info
42+
print(df.head())
43+
print(df.info())

0 commit comments

Comments
 (0)