Lec4 - 4 More on Conditionals Nested if's Multiple...

Info icon This preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
4. More on Conditionals Nested if’s Multiple Alternatives
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Recall the if-else “Template” if end else boolean expression Commands to execute if the expression if TRUE Commands to execute if the expression if FALSE
Image of page 2
Question Time Variables a, b, and c have whole number values. True or false: This fragment prints “Yes” if there is a right triangle with side lengths a, b, and c and prints “No” otherwise. A. True B . False if a^2 + b^2 == c^2 disp(‘Yes’) else disp(‘No’) end
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
a = 5; b = 3; c = 4; if a^2 + b^2 == c^2 disp(‘Yes’) else disp(‘No’) end Prints “no” even though we have: 5 4 3
Image of page 4
if disp(‘Yes’) else disp(‘No’) end The boolean expression should be true if a 2 +b 2 =c 2 or a 2 +c 2 =b 2 or b 2 +c 2 =a 2 is true. a^2 + b^2 == c^2 (a^2+b^2==c^2) || (a^2+c^2==b^2) || (b^2+c^2==a^2)
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Developing “If” Solutions Illustrate the thinking associated with the design of if statements. The methodology of stepwise refinement . Two examples...
Image of page 6
Write a script that solicits a positive integer Y and prints the number of days in year Y as determined by the Gregorian calendar. Problem 1
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Leap Year Rule A non-century year is a leap year if it is divisible by 4. A century year is a leap year only if it is divisible by 400.
Image of page 8