I am trying to find all possible angles and sides in a given shape. However, I am struggling. This is the start of my code.
SidesNumber = int(input("How many sides does your shape have: "))
SidesNumber = str(SidesNumber)
ShapeName = input("What is your shape's name. Please enter "+ SidesNumber +" letters: ")
SidesNumber = int(SidesNumber)
while (len(ShapeName) != SidesNumber) or(not ShapeName.isalpha()):
if (len(ShapeName) != SidesNumber) and(not ShapeName.isalpha()):
print("Your input does not match the number of vertices your shape has and does not consist of only letters!")
SidesNumber = str(SidesNumber)
ShapeName = input("What is your shape's name. Please enter "+ SidesNumber +" letters: ")
SidesNumber = int(SidesNumber)
elif len(ShapeName) != SidesNumber:
print("Your input does not match the number of vertices your shape has!")
SidesNumber = str(SidesNumber)
ShapeName = input("What is your shape's name. Please enter "+ SidesNumber +" letters: ")
SidesNumber = int(SidesNumber)
elif not ShapeName.isalpha():
print("Your input does not consist of letters only!")
SidesNumber = str(SidesNumber)
ShapeName = input("What is your shape's name. Please enter "+ SidesNumber +" letters: ")
SidesNumber = int(SidesNumber)
Now what I want to do is to get the computer to calculate all the different angles and sides based on the users' inputs. So if they enter SidesNumber and ABC for the ShapeName I want the computer to find all the angles and sides or all the possible outcomes in other words. So the angles should be ∠ABC, ∠ACB, ∠BAC. And the sides should be AB, BC, AC.
Furthermore, I want these results to be saved in different variables, something like side1 = 'AB'
and side2 ='BC'
and side3 = 'AC'
. For angles something like angle1 = '∠ABC'
and angle1 = '∠ACB'
and angle1 = '∠BAC'
I already of this code:
import itertools
dataset = ['1','2','3A','4']
var = list(itertools.combinations(dataset, 3))
print(var)
But it seems to be useless for me.
I'm not sure I completely follow your description of what you're trying to do, but think these examples of generating the outcomes might be helpful:
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = [iter(iterable) for _ in range(2)]
next(b, None)
return zip(a, b)
# hardcode a name for non-interactive testing
shape_name = 'ABC'
sides = [''.join(pair) for pair in pairwise(shape_name + shape_name[0])]
print('sides: {}'.format(sides))
def angle_name(shape_name, side):
this = shape_name.index(side[-1]) # index of letter for end of this segment
try:
nx = shape_name[this+1] # get letter for next segment
except IndexError:
nx = shape_name[0] # wrap around
return '∠'+side+nx
angles = [angle_name(shape_name, side) for side in sides]
print('angles: {}'.format(angles))
Output:
sides: ['AB', 'BC', 'CA']
angles: ['∠ABC', '∠BCA', '∠CAB']
Regardless, I also strongly suggest you read and start following to PEP 8 - Style Guide for Python Code, particularly the Naming Conventions section.