Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming exercise 3: Magic square validator A 3x3 magic square is a 3 by 3 square arrangement of digits between 1 and 9 (without duplicates)
Programming exercise 3: Magic square validator A 3x3 magic square is a 3 by 3 square arrangement of digits between 1 and 9 (without duplicates) such that the sum of any 3 digits horizontally, vertically, or diagonally equals 15. You can read more about these on the Wikipedia page for magic squares. Your program will take a potential magic square from user input and validate whether the input is a magic square Take the input as three separate lines from the user (you can use a loop to get three lines one after the other. Using input() without an argument will let the user input another line without any printed prompt.) Each line should consist of three numerical characters. Once all three lines have been entered the program will evaluate whether or not the three rows form a magic square and report the result. For example, in this case, the numbers do add up to 15 in all 8 directions (three horizontal rows, three vertical columns, and two corner-to-corner diagonals): $ python magic_square_validator.py Enter a, magic number 492 357 816 This is a magic square! If the input values do not add up to 15 in all 8 directions, your program will report that the input square is not a magic square $ python magic_square_validator.py Enter a magic number 123 456 789 Not a magic square! Consider what would need to change to generalize this validator to squares of arbitrary sizes (you don't need to code this for the lab, but please think about what you would do differently)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started