Interior angle sum generator 11-07-2013, 01:37 AM
#1

Coded this in 40 minutes during lunch as extra credit for math. Thats why its so commented. The bitch never "got around to it," so I'm releasing this to display the implementation of formulas in python. The formula used is 180(n-2) where n is the number of sides.

Code:

`import sys`

#creates a main menu

def menu():

#writes a welcome message

print "Welcome to my interior angle sum generator!"

raw_input('Press any key to continue...')

#Asks for an input to make a selection

x = raw_input('Enter 1 for a single value \nEnter 2 for a list of values: ')

#if the input is equal to 1 it will call the first option

if int(x) == 1:

individual()

#if the input is 2 it will call the second option

elif int(x) == 2:

array()

#If a number other than 1 or 2 is entered it will give an error

else:

print "Please enter a valid number!"

def menu2():

x = raw_input('---------------------------\nEnter 1 for a single value \nEnter 2 for a list of values\nEnter 3 to exit: ')

#if the input is equal to 1 it will call the first option

if int(x) == 1:

individual()

#if the input is 2 it will call the second option

elif int(x) == 2:

array()

#If a number other than 1 or 2 is entered it will give an error

elif int(x) == 3:

sys.exit('Thank you for using Int Sum Generator by Ryan Shtirmer!')

else:

print "Please enter a valid number!"

#creates a function for one polygon with the given number of sides

def individual():

#asks for an input of the number of sides

n = raw_input('Number of sides: ')

#Checks if the input is less than 3

if int(n) < 3:

print "Please enter a number above 3!"

individual()

#Runs and displays the formula

if n >= 3:

x = int(n)-2

print x * 180

raw_input('Press any key to continue...')

else:

individual()

menu2()

#Creates a function to make a list of angles sums between 3 and the inputted number

def array():

#number of sides is 3

n=3

#Asks for the highest number of sides

z = raw_input('Highest Number of sides: ')

#Checks if the number is less than 4 or greater than 500

if int(z) < 4:

print "Please enter a number greater than 3!"

array()

if int(z) > 500:

print "Please enter a number less than 500!"

array()

#Runs the formula on all numbers between 3 and the given number

if int(z) >= 4 and int(z) <=500:

while n<int(z):

x=n-2

print str(n) + ":" + str(x * 180)

n+=1

raw_input('Press any key to continue...')

menu2()

else:

array()

menu()

#MakeSinisterlySexyAgain