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.
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!
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).
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.
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
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.
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.
Therefore 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 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.
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.
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.