Mastery Topics – #TC1017 (Python3)

--Originally published at TC1017 (Python3) – Titel der Website

Dear friends,

30 minutes ago, I had an appointment with Ken. Yes, we all know, that we normally program with C++ in this course. But Ken gave me at the beginning of the semester the great opportunity to program with python3 in this semester.

So a lot of things/codes are in python much easier and shorter than in C++. That was the reason for my appointment with Ken. Because of this reason i agreed with Ken that I am going to do a huge blog post with 15 mastery topics.


Mastery Topic #1 – Use of comments


For a comment you just use the Hash symbol (#). What makes the comment to a comment, ist that every symbol after the # is grey.


Mastery Topic #2 – Python conventions (Zen of Python)

The Zen of Python

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!


Mastery Topic #3 – Basic types and their use

Basic (or also primitiv) types in python are: Integer, floats, strings, characters

Continue reading "Mastery Topics – #TC1017 (Python3)"

Estimating e – (WSQ12)

--Originally published at TC1017 (Python3) – Titel der Website

What To Do

In this assignment you will estimate the mathematical constant e. You should create a function called calculuate_e which receives one parameter called precision that should specify the number of decimal points of accuracy.

You will want to use the infinite series to calculate the value, stopping when the accuracy is reached (previous and current calculation are the same at the specified accuracy).


My Sourcecode:

WSQ12 - SourceCode.PNG

The result:

WSQ12 - Ergebnis.PNG

Go Bananas – (WSQ11)

--Originally published at TC1017 (Python3) – Titel der Website

What was to do in this WSQ:

Write a function called find_bananas which receives a single parameter called filename (a string) and returns a positive integer which is the number of times the word (string) “banana”  (or “BANANA” ) is found in the file. The banana can be any case (‘BaNana’ or ‘BANANA’ or ‘banana’, etc) and they can be “stuck together” like “banAnaBANANA” (that counts as two). Create your own test file (plain text) to check your work.

My Banana File:

WSQ11 - TextDatei.PNG

My Sourcecode:

WSQ11 - SourceCode.PNG

The result:

WSQ11 - Ergebnis.PNG

Multipart Data and Files – (WSQ09)

--Originally published at TC1017 (Python3) – Titel der Website

The assignment:

So for this assignment I would like to see you create a function that receives as parameter the name of a file (this would be a string value like data.txt) and your function counts the number of lines and the number of characters in the file which it returns as a single value (but with two values). You will want to look at how to create/define and return a struct value from a function and how to open and read text files line by line


My text data:

WSQ09 -

My Sourcecode:

WSQ09 - SourceCode.PNG

The result:

WSQ09 - Ergebnis.PNG

WSQ07 – Lists (total, average and standard deviation)

--Originally published at TC1017 (Python3) – Titel der Website

Hello Guys,

after a long time its me again! Sercan aka. Sergio


I had a big problem with the standard deviation while i was doing this WSQ. Actually i didn´t even found something in the internet how to program this that. Well, to solve the problem i needed help from the Superheroprogrammerwithstil Ken. So I made an appointment with him to talk about this issue.

The result of the source code is, that i implement with Ken a lot of new Python code, which i didn’t knew before.

SourceCode - WSQ07.PNG

Python has his own Math library. That means, if you don´t call the library or a specific function of the library, python is not able to do things which you want to do. In line 1 e.g. i call the specific math function sqrt. But to make sure that all math functions are reachable, i just call them with import math.

To make sure that don´t program unnecessary code for the input of 10 numbers I just programmed a for loop until the User gives the program 10 Numbers.

To unterstand the lines from 16 – 25 we need to know how the standard deviation works.

standardabweichung-berechnen-beispiel-1-2.jpgTherefore the formula.


So we need the total for the average and the average for the fraction of the st. dev.

After we have that all, we just use the math function to make sure that we extract the root.


The result is:

WSQ07 - Ergebnis - Lists.PNG


Enjoy Fellas.

Factorial Calculator (WSQ06)

--Originally published at TC1017 (Python3) – Titel der Website

Hello Guys,


the WSQ06 was for me, until now, the hardest program to write. The most time I lost with thinking about the program-structure. Like Ken once told us: „Sometimes it is better to delete all your coding and start from the beginning“.

Although it was an overcoming for me I had to do 2 times a Reengineering.

The second thing was the way to count the Factorial. Since now I did the Factorial always with the Calculator and never thought about how the calculator would be programmed to get the result of the Factorial.

Nevertheless, I found a good way to program the Factorial.

My Source-Code:

WSQ06 - SourceCode - Fak.PNG

My result:

WSQ06 - Ergebnis - Fak.PNG


If you have a question, just ask me.

I am going to try to help you Guys.




Fun with Numbers and Functions (WSQ05)

--Originally published at TC1017 (Python3) – Titel der Website

Hello Guys,

this is the continuation of the WSQ01 (Fun with numbers).

The task here was, to calculate the numbers of User with functions.

To understand how Functions work on Python3 i found the following video.


Which i have not found is how to work with a return value.


The Program:

WSQ5 - SourceCode - FunWithNum2.PNG


The Result:

WSQ5 - Ergebnis - FunWithNum2.PNG




The Sum of Numbers (WSQ – 04)

--Originally published at TC1017 (Python3) – Titel der Website

In this WSQ we had to write a program, which asks you for a range of integers and than prints the sum of the numbers in that range.

For example the range from 6 to 10.

For Mathematical operations lime this there is a formula.


But this formula is from 1 – n…

If you have something from n – m you have to use this formula 2 times and then build the difference.

You can see this operation in my program.

WSQ04 - SourceCode - SumNumbers.PNG


The result:

WSQ04 - Ergebnis - SumNumber.PNG

Guess the random number (WSQ 03)

--Originally published at TC1017 (Python3) – Titel der Website

The task was to write a program were the User have to guess the random number between 1 – 100. The random number is to be selected by the program.

After the guess the program have to tell you if your guess is to low or to high. And every time when the user do a guess, the sum of the guesses should be counted. When the User finally guesses the correct number, the program have to say that it is the correct number with the sum of the tryings.


The problem

Before a could start to write the program i had to inform myself for the issue with the random number. I never had a task like this with eclipse before. So I had no idea how program a random number between 1 – 100.

In my internet research i found a simple video for this problem.


The biggest challenge in this program was to build a loop while the user dont get the random number wich was chosen from the program.

The keyword while helped me a lot in this case. So i just choose a while loop wich i knew from Java programming.

The program

WSQ03 - SourceCode- RandomNumber.PNG


The result

WSQ03 - Ergebnis - Random Number.PNG