if and else: two ways to go
Now the decision. The program reads a number, tests the condition num % 2 == 0, and shows one message if it is true and another if it is not. Look at the details. The test uses two equal signs, because one = stores a value in a variable and two == ask a question. The lines if ...: and else: end with a colon. The lines under them are indented by four spaces; this tells Python which lines belong to which branch. A line that is not indented, such as the last line below, runs in every case. In the flowchart, the diamond is the decision with a yes arrow and a no arrow. When the user types 7, the remainder is 1, the condition is false, and the screen shows Odd number.
1num = int(input("Enter a number: ")) 2if num % 2 == 0: 3 print("Even number") 4else: 5 print("Odd number")
Enter a number: 12 Even number
1num = int(input("Enter a number: ")) 2if num % 2 == 0: 3 print("Even number") 4else: 5 print("Odd number") 6print("Done")
Enter a number: 7 Odd number Done
On paper, change the program so that it says Positive when num > 0 and Not positive otherwise. Draw the flowchart with the diamond, and say what the screen shows for -3, 0 and 8.