Ok folks Hello and welcome back to my new series of "Cracking CS50P: A DevAdvocate's Python Guide", today we are going to dive into how I tackled the fourth problem in Problem Set 0: "Einstein" (einstein.py).
And if you didn't read the previous article I mean Making Faces or we can say faces.py then trust me you are missing the important detail in the python language. And as you know I am here to guide you in how to solve the problems I am not telling the exact answers to any problem set because you have to learn it by yourself.
_**
Recap of 3rd Article einstein.py........
_In the previous we saw that how to replace more than one string to something else in the cool and short way because in the 2nd part we saw the same thing but that was long and hard to read so here's how we did that first we have to select the part that we want to replace with the other part or the string and then we write _.replace() **in the brackets we hsve to write what we have to replace with what like [eg., .replace("/", "?") ] and if we want to replace more tha one string at the same time in our program we can write it like eg., [.replace("/", "?").replace("", "=")]. So this is how we can replace as many string we like in the one line of code. So moving to the the next target.
And, No I didn't make any mistakes this time 😎........
**_
Let's start 3rd Article faces.py........
**
In this part we are going to see how to do math or how to make the program solve math problems. Sound so cool right and it is cool as it sounds. So, Let's get started shall we,.
So, in this particular situation we can assign any particular value to the _variable **_and then make the program do calculations like _sum, multiply, divide, etc**. Like in this case or we can say in this problem we have to assigned the value of speed of light to the variable and multiply it to the user input number. Like the speed of the light is 3 lakh km/sec right so we have to multiply it to the random number that user will input in the terminal.
So in this place we will use the most famous formula of Einstein E = mc² as we all know E is energy, m is mass and c is speed of light. And remember that we have to multiply c two times because it is square.
So, this are the all hints I can give you right now if you have any doubts about this article feel free to watch on my youtube channel or you could directly ask me in the comment section. Ok so we will meet again soon Goodbey till then.
Top comments (0)