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

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

4. More on Conditionals Nested if’s Multiple Alternatives

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

View Full Document
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
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

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

View Full Document
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
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)

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

View Full Document
Developing “If” Solutions Illustrate the thinking associated with the design of if statements. The methodology of stepwise refinement . Two examples...
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

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

View Full Document
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.