+ 1

How to find logic for any kind of program?

Programming language

19th Nov 2019, 4:44 PM
Pon Balaji
Pon Balaji - avatar
4 Respostas
+ 7
By thinking. This sounds tongue-in-cheek, but it's true anyway. 😉 Trick is, while learning a language, to look for simple tasks that you *can* figure out with a bit of thinking. No problem, if they are very easy in the beginning. Over time, you will get used to translating a real life problem into code, so you'll gradually be able to translate more complicated tasks.
19th Nov 2019, 4:48 PM
HonFu
HonFu - avatar
+ 2
When there is a task, that you need to do in code, first of all you should break the task for steps, and make an alghoritm. I will show, how I do it. For ex., I have a task: "Write temperature converter C / K. User inputs temp. like this "52 C" or "378 K", your task is to convert it into Celcium or Kelvin." Now I start solving this task firtly in my head. My minds: Ok, so my programm will need an input and will give an output. So I am going to use functions. First of all I am checking, is temperature given in C or in K, so I should divide the input using split() method, and I am going to make 2 variables, temp for temperature, sys for system. Secondly, I am going to make two if statements, if sys equals to C, then return K, calculated by formula, else if sys equals to K, then return calculated by formula C. Ok, finally my function is ready, but user can input invalid input, so I am implementing third else statement, it will triger, if sys is not K, nor C, and return None. Good luck!
19th Nov 2019, 5:23 PM
Asman-H
Asman-H - avatar
+ 1
Yeah absolutely true HonFu
19th Nov 2019, 5:07 PM
Pon Balaji
Pon Balaji - avatar
+ 1
Thanks Asman-H
20th Nov 2019, 5:45 AM
Pon Balaji
Pon Balaji - avatar