+ 1

I'm overthinking control flow questions.

Please open below link in new tab and see lines 1-37 https://code.sololearn.com/c9KIG0ab38pI I am not sure if my methods are correct I think they are but I am not certain and over analyzing. I also test my solutions by changing the constants around making sure the rules fall into place with the objective. Should I be changing the constants around to check work? When I do I find some rules not complying with the objective but if I build the code around the constant and never change them I can make the code work. The first code block is fine when I change constants to check work but the second one I am struggling with the isRaining constant and whether or not the NOT operator should be there. Please assist.

18th Dec 2018, 12:57 AM
Ran9
Ran9 - avatar
3 Answers
+ 2
Yep it's best to not overthink it. > it's not raining !isRaining > 82 degrees or warmer temp >= 82 > it's sunny isSunny Then connect it up, replacing "or" with `||` and "and" with `&&`. !isRaining || (temp >= 82 && isSunny) It's actually funny because you could read the same sentence of the description as (!isRaining || temp >= 82) && isSunny English is imprecise like that.
18th Dec 2018, 4:45 AM
Schindlabua
Schindlabua - avatar
+ 4
Personally, I would make the tests a function with parameters for the conditions. Then you could test all or reasonable cases (temp of [80,81,82,83, 84]) in one run. I didn't run the code so I make no promises of being thorough, but line 30 and 33 are wrong. let isNiceWeather = !isRaining || (temp >= 82 && isSunny) print("I'm going for a walk!") Given that isSunny is true only when isRaining is false, logically !isRaining would be the only test required. However, you can code it so both raining and sunny are true and walking depends on the temp.
18th Dec 2018, 5:04 AM
John Wells
John Wells - avatar
+ 2
@Schindlabua : Thanks. @JohnWells: I had a few options In mind similar to yours using function and parameters but I'd like to answer the question with the if-else statement as directed in the practice question. and thanks for answering.
20th Dec 2018, 2:13 AM
Ran9
Ran9 - avatar