filmov
tv
Converting Strings to Integers Nested Lists in Python

Показать описание
This is from a file import; However, I highlighted the pertinent code:
#Python #NestedLists #integers
# Ralph Turchiano Coverting Strings to Intergers in Nested Lists
from math import sin, cos, tan, asin, acos, atan2, radians, degrees, sqrt
def find_net_force_from_file(x):
pforces = []
forces=[]
total_horizontal = 0
total_vertical = 0
ipt = open(x,"r")
print(lines, "---------------Raw Import as texts with line breaks","\n")
for kk in lines:
print(pforces,"------File imports as Strings (strip)", "\n")
for yy in pforces:
print(forces,"Problem Nested Lists composed as Strings (split)", "\n")
######################################################
tu = 0
for jj in range(len(forces)):
forces[tu][0] = int(forces[tu][0])
forces[tu][1] = int(forces[tu][1])
tu+=1
######################################################
print(forces,"-------------Here we are all coverted to Intergers (Solved)","\n")
for force in forces:
magnitude, angle = force
angle = float(radians(angle))
horizontal = magnitude * cos(angle)
vertical = magnitude * sin(angle)
total_horizontal += horizontal
total_vertical += vertical
net_magnitude = sqrt(total_horizontal**2 + total_vertical**2)
net_magnitude = round(net_magnitude, 1)
net_angle = atan2(total_vertical, total_horizontal)
net_angle = degrees(net_angle)
net_angle = round(net_angle, 1)
return (net_magnitude, net_angle)
#Python #NestedLists #integers
# Ralph Turchiano Coverting Strings to Intergers in Nested Lists
from math import sin, cos, tan, asin, acos, atan2, radians, degrees, sqrt
def find_net_force_from_file(x):
pforces = []
forces=[]
total_horizontal = 0
total_vertical = 0
ipt = open(x,"r")
print(lines, "---------------Raw Import as texts with line breaks","\n")
for kk in lines:
print(pforces,"------File imports as Strings (strip)", "\n")
for yy in pforces:
print(forces,"Problem Nested Lists composed as Strings (split)", "\n")
######################################################
tu = 0
for jj in range(len(forces)):
forces[tu][0] = int(forces[tu][0])
forces[tu][1] = int(forces[tu][1])
tu+=1
######################################################
print(forces,"-------------Here we are all coverted to Intergers (Solved)","\n")
for force in forces:
magnitude, angle = force
angle = float(radians(angle))
horizontal = magnitude * cos(angle)
vertical = magnitude * sin(angle)
total_horizontal += horizontal
total_vertical += vertical
net_magnitude = sqrt(total_horizontal**2 + total_vertical**2)
net_magnitude = round(net_magnitude, 1)
net_angle = atan2(total_vertical, total_horizontal)
net_angle = degrees(net_angle)
net_angle = round(net_angle, 1)
return (net_magnitude, net_angle)
Комментарии