英文:
Stuck on nested if statement challenge
问题
我尝试创建一个嵌套的if语句,以便测试第一个和第二个if语句是否为真,如果为真,则打印出语句“两个语句都为真”。
英文:
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?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论