Answered step by step
Verified Expert Solution
Link Copied!

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)

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 1 Lnai 9851

Authors: Paolo Frasconi ,Niels Landwehr ,Giuseppe Manco ,Jilles Vreeken

1st Edition

3319461273, 978-3319461274

More Books

Students also viewed these Databases questions

Question

manageremployee relationship deteriorating over time;

Answered: 1 week ago