Python Forum
Length and direction cosines of lines - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Length and direction cosines of lines (/thread-22489.html)



Length and direction cosines of lines - tarikrr - Nov-14-2019

Good day,

First time posting, and new to python
I'm trying to get the user to input the number of lines he wants, then input the coordinates for the line ends for each line

say the user enters the number of lines: 10
then how can I prompt him to input the x y coordinates for each line end for each line (10 times for example)
then store those coordinates to do some operations on it like finding each line length and finding each line direction cosines?


thank you!


RE: Length and direction cosines of lines - SheeppOSU - Nov-15-2019

The first part of getting the input is rather easy. Here's the code to do so
numberOfLines = input('Enter the number of lines you want: ')

alphabetList = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'J', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y' ,'Z']
lineDict = {}

for x in range(0, int(numberOfLines)):
    count = 1
    while x > 25:
        x -= 25
        count += 1
    if count > 1:
        label = f'{count}{alphabetList[x]}'
    else:
        label = f'{alphabetList[x]}'
    lineDict.update({label : input(f'Enter the x and y coordinates for line "{label}" separated by commas, for example: 3, -1\n').split(',')})
Here my output from testing it
Output:
Enter the number of lines you want: 10 Enter the x and y coordinates for line "A" separated by commas, for example: 3, -1 10, 1 Enter the x and y coordinates for line "B" separated by commas, for example: 3, -1 2, 9 Enter the x and y coordinates for line "C" separated by commas, for example: 3, -1 0, -35 Enter the x and y coordinates for line "D" separated by commas, for example: 3, -1 -1010, 1 Enter the x and y coordinates for line "E" separated by commas, for example: 3, -1 3, -3i Enter the x and y coordinates for line "F" separated by commas, for example: 3, -1 1, 9 Enter the x and y coordinates for line "G" separated by commas, for example: 3, -1 -4, 70i Enter the x and y coordinates for line "H" separated by commas, for example: 3, -1 5, i Enter the x and y coordinates for line "I" separated by commas, for example: 3, -1 2, -i Enter the x and y coordinates for line "J" separated by commas, for example: 3, -1 1, 0 {'A': ['10', ' 1'], 'B': ['2', ' 9'], 'C': ['0', ' -35'], 'D': ['-1010', ' 1'], 'E': ['3', ' -3i'], 'F': ['1', ' 9'], 'G': ['-4', ' 70i'], 'H': ['5', ' i'], 'I': ['2', ' -i'], 'J': ['1', ' 0']}
You can then cycle through the dictionary and do operations on all the lines. The only thing I haven't tested is using more than 26 lines, so I don't know if that works properly