Stuck on nested if statement challenge.

huangapple go评论58阅读模式
英文:

Stuck on nested if statement challenge

问题

我尝试创建一个嵌套的if语句,以便测试第一个和第二个if语句是否为真,如果为真,则打印出语句“两个语句都为真”。

英文:

Nested If Statement Challenge

Copy of Code

Any guidance on this would be appreciated!

I tried to create a nested if statement so that the first and second if statement would be tested for truth and if it is true, then the statement "Both statements are true" is printed.

答案1

得分: 1

你需要打印出“程序结束。”,无论这四个数字是什么。目前,你将这行放在了一个else块中,所以只有在 num1 >= num2 评估为false时才会打印出来。请记住,if语句并不总是需要相应的else语句。

另外,else if语句可以被替换为else语句。我鼓励你考虑一下为什么会这样。提示:程序已经必须满足了什么条件才能达到else if?

英文:

You need to print "Program ended." no matter what the four numbers were. Currently, you have that line in an else block, so it only prints if num1 >= num2 evaluated to false. Remember that an if statement doesn't always need a corresponding else statement.

Also, the else if statement can be replaced with an else statement. I would encourage you to think about why that is. Hint: what already had to be true for the program to reach the else if?

huangapple
  • 本文由 发表于 2023年6月8日 10:37:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76428239.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定