Complete the code to identify the file extension for STL files.
filename = "model[1]"
The STL file format uses the .stl extension, which is standard for 3D printing models.
Complete the code to check if an STL file is in ASCII format by reading its first 5 characters.
with open('part.stl', 'r') as file: header = file.read([1]) is_ascii = header == 'solid'
The ASCII STL files start with the word solid, which has 5 characters.
Fix the error in the code to correctly parse the number of triangles from a binary STL file header.
with open('shape.stl', 'rb') as f: f.read(80) # skip header num_triangles = int.from_bytes(f.read([1]), byteorder='little')
The number of triangles in a binary STL file is stored as a 4-byte unsigned integer after the 80-byte header.
Fill both blanks to create a dictionary comprehension that maps each triangle index to its normal vector length in an STL model.
normals_length = {i: (nx[1]2 + ny[2]2 + nz**2)**0.5 for i, (nx, ny, nz) in enumerate(normals)}To calculate the length of a vector, square each component (using **2), sum them (using +), then take the square root.
Fill all three blanks to create a filtered dictionary of triangles with area greater than zero from STL data.
filtered_triangles = [1]: [2] for [3], [2] in triangles.items() if [2] > 0}
The dictionary comprehension uses index as key, area as value, and i as the loop variable for keys in triangles.items(). It filters areas greater than zero.