Individual Reflection about „Spring Semester Calendar“

Already the brainstorming was an exciting process. Our goal was to create something individual that is not a 08/15 program from the Internet, but one that even generates a benefit.

Since our group consists exclusively of internationals, we thought together about what moved us especially in this semester and whether it could be integrated into a Python program. When we thought about how quickly the time had passed away at TEC, we came up with the idea of programming a calendar for the upcoming semester.

This calendar should not only contain the semester start and end, but also the exam phase and holidays, which the student can use for weekend trips.

It was also our goal to implement a function that prevents an invalid date entry. In order to make the program as simple as possible, we have created a list for the number of days per month in the coming semester. This list enabled us to assign the number of days to each month just once.

When we were almost finished with the project, we thought again about an exciting feature that could bring us a special personal benefit and would set us apart from a classic calendar. We agreed that it is exciting to know at any time in which phase of the semester you are currently in. In order to do this, we programmed another function that shows the student the days he has spent at the TEC so far and the days he has left, as the time at the TEC went by faster than we could have imagined. With the help of a loop, we determined the current day of the year and then calculated the phase of the semester.

Programming in a team was a lot of fun and opened a new perspective for me. To a certain extent, each of us has our own strengths and this can lead to synergy effects that produce particularly good results. When programming on my own, I sometimes had the problem that I got lost in a problem. By working with other team members, I was able to solve any problems much faster.

One of my particular strengths would be my ability to think logically, but I still tend to be too much in my tunnel and forget to look left and right, so working in a team makes a lot of sense to me.

All in all, the project was an exciting experience at the end of which I was able to reflect on and apply the knowledge I had learned.

How to handle Strings

Each character of a string can be reached with an index number, each string starts with the 0 index.

In order to output the part of a string, you have to consider the following: s[startIndex:pastIndex].
pastIndex is the length of a string + 1.

With the s.replace(„“,“““) operator you can replace parts of a string.

You can also compare two strings or search for words in a string:

More useful String Methods:

Source: https://pythonspot.com/strings/

Mutable and Immutable

Lists and tuples are two data structures in Python that can be used to combine data into one unit.
Both data structures allow read access to the individual data.
While the data structure list allows a write access, such a write access is not possible with tuples.
Lists are data objects that can be changed in Python, tuples are data objects that cannot be changed.

Lists are surrounded by square brackets and separated by commas. [1, „Who will be the champion?“, 1904]
Numbers can simply be entered into the list, strings, on the other hand, must be enclosed in quotation marks.
Furthermore, there is the possibility of a nested list [[„Gelsenkirchen“, „Nürnberg“],[1900,1904],[„echte“, „Fanfreundschaft“]] or a deeply nested list [„Fußballclub“,[„Gelsenkirchen“,[„Schalke“,[„1904“]]]]

A tuple can be imagined as an unchangeable list. Tuples are defined in the same way as lists, except that round brackets are used instead of square brackets: („tuples“, „are“, „immudable“)
If it is known that data does not have to be changed, tuples should be used to avoid unwanted changes.

Source: https://www.python-kurs.eu/python3_sequentielle_datentypen.php

Which Repetition?

In the last article we dealt with recursions and considered the faculty as an example of recursion:

It turned out that the use of recursions with a high recursion depth can lead to an impairment of computer performance.
One approach to solve this is the bottom-up approach. Instead of recursive programming, a while loop is used, which multiplies the numbers from 1 to n:

As we can see, it is not always clear which method of repetition (while, for, recursion) makes sense in which case. Often you can use several methods, but solving the problem with one method may be more difficult than with the other.

Again and again

We say these words again and again

But they still sound the same to me

Say these words again and again

And again and again

Keane

Recursion is a function that calls itself again and again. The standard example is the faculty of the number n. It is the product of all natural numbers less than or equal to this number n.
This function, expressed recursively in Python, looks as follows:

A problem of recursions is the slow calculation speed.

There is no end…

… but there need to be one if you are operating with loops in Python.
In genereal you have two possibilites:

  1. Using a while-loop
  2. Using a for-loop

A while loop always starts with the word while. Then follows a condition and a colon.
Normally, a loop is only terminated if the condition in the loop header is no longer fulfilled. With break you can leave a loop prematurely. This is important if you use while: true, for example.

The for statement in Python is different from the for loop in other computer languages.
In Python, the for loop is for iteration over a sequence of objects.
The range() function is particularly useful in conjunction with the for loop.

In this example it is important to note the following:

  • the first digit indicates the lower limit
  • the second digit indicates the upper limit, but you have to specify your desired value n+1
  • the third digit indicates the step size

If you read this blog post…

… you will know how to use conditionals in Python.

‚If-Sentences‘ are not only important in the English language but also in the computer language.
With them it is possible to print conditions. Using the following example, which checks whether the given pages are a triangle, I would like to explain the use of ‚if‘ in Python.

In line 7 the basic condition for a triangle is checked first. If this condition is not fulfilled, the program jumps directly to line 14 and it is shown that it is not a triangle.
If the condition is fulfilled, I have a put another nested if-condition. The program then checks whether it is an equilateral triangle.
If this is not the case, but you want to query another condition, use elif.
If the triangle is not isosceles either, it is a normal triangle.

Modules

If a program is too long, it may be useful to split it into several files. If you have definied functions, it is also useful to be able to use them in several programs.
A module is a file which is defined in one file and can be reused in another file and which contains Python definitions and applications.

There are:

  • Standard libraries, custom libraries and third-party libraries
  • Local modules that are only available for one program

A library is included with the import statement. A standard example is the import of the Mathmodule, which provides mathematical constants and functions.
Several modules can be imported separated by a comma: Import math, random

For an overview, these are usually written at the beginning of the program.
If you want to use e.g. Pi, you have to specify the name of the function when using the constants: math.pi
Alternatively you can just import Pi and don’t have to specify the name of the module explicitly: from math import pi
If you add an as to the import command, it is possible to rename the function: import math as algebra
With the dir function you can display the names defined in a module: dir(math)

If you have written a program in which you have defined a function, for example, you can import it as a module into a new program, provided it is stored in the same file path as a Python file (.py). For this you simply use: import name

The Function of a Function is to Function

User-defined functions are reusable code blocks. They only need to be written once, then they can be used multiple times. They can even be used in other applications, too.

In Python a function is defined using the def Keyword.
To call a function, use the function name():

With the Return command, you can return values of a function:

Depending on the function definition, one function can be called with zero, one, two or more parameters.

https://pythonspot.com/method-overloading/
Erstelle eine Website wie diese mit WordPress.com
Jetzt starten