Category : Python or overall
Inspiration
In AP Computer Science Principles we have a final project where we have to create a program that must fulfill the requirements listed by College Board. My code was aimed at finding the nth roots of unity, which is 1. I had made that original project in Snap!, the language we used in that class. I decided to replicate that same project in python to test my skills.
What is the nth Root of Unity
Unity is just a fancy name of 1 the natural number 1. Suppose there is an equation x^7 = 1. We know that one solution is x =1 . But, there are 6 distinct complex roots that we are unaware of. All these 7 roots are the 7th roots of unity. Similarly there are roots of 1 for all natural numbers
What it does
The code simply prompts the user to enter the value of 'n', for which we will find the roots of 1. When the user enters something, the code checks if it is a natural number and if it's not, then it prompts the user to enter a value again. When the user finally enters a natural number (n in this case), the code prints all the real and complex roots of 1 based on the value of 'n'.
How we built it
I started with building a function to check if the user's entry is a natural number. Then, I built the main function that does all the math and prints the roots based on the user input.
Challenges we ran into
I wanted to make this code error-free and keep going till a user gets an actual result or a sequence. That is the purpose of the first function of the code to enable the user to try again if they put an invalid value in their first try. For example, even if the user enters "3h" as a value, the code will let them try again and enter a natural number.
Accomplishments that we're proud of
One thing I am proud of that this code is error free and keeps going until it returns real a list of roots.
What's next for nth Root of Unity
This code will be extremely useful to people working in science fields like quantum computing where the use of complex numbers is really common. Instead of doing the tedious task of finding all the roots separately, this code lists all of them in a few seconds
Log in or sign up for Devpost to join the conversation.