Complex Number Validation
Combine positivity, parity, digit count, and digit-sum rules. Students use named booleans and see why every condition must be checked before acceptance.
1# Take a number2num = int(input("Enter a number: "))34# Check multiple conditions5is_positive = num > 06is_even = num % 2 == 07is_two_digit = 10 <= num <= 998sum_of_digits = sum(int(d) for d in str(abs(num)))9sum_is_even = sum_of_digits % 2 == 01011if is_positive and is_even and is_two_digit and sum_is_even:12 print("Number meets all criteria")13else:14 print("Number does not meet all criteria")
Output
Enter a number: 24 Number meets all criteria Enter a number: 25 Number does not meet all criteria
In this one
- Name independent predicates
- Reject a negative input safely
- Require every condition
How it works
- 1
Read num and calculate positivity, parity, and digit-size booleans.
- 2
Sum digits of abs(num) and test that sum's parity.
- 3
Combine all four booleans with and.
Edge cases
What happens for 24?
What happens for 24?
All four criteria pass.
Why scan str(abs(num))?
Why scan str(abs(num))?
It prevents trying to convert a negative sign into a digit.
What's going on
Despite its title, this is an integer-rule validator, not Python complex-number arithmetic. It requires a positive even two-digit value whose digit sum is even.
Named booleans make each condition inspectable before the final and chain. Input 24 passes with digit sum six; 25 fails parity. The digit scan must use the magnitude, since attempting int('-') for negative input would fail before rejection.
What happens for 24? All four criteria pass.
Why scan str(abs(num))? It prevents trying to convert a negative sign into a digit.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Does one passing rule suffice?
Pick an answer to check it.
Question 2
What happens for 24?
Pick an answer to check it.
Questions people ask
What happens for 24?
All four criteria pass.
Why scan str(abs(num))?
It prevents trying to convert a negative sign into a digit.
Does one passing rule suffice?
No, every named condition must pass.
๐Related Content
- ๐
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- ๐
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- ๐ป
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum