Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import math def calculate _ properties ( metal _ name, metal _ prices, metal _ densities, metal _ resistivities ) : # Find the index

import math
def calculate_properties(metal_name, metal_prices, metal_densities, metal_resistivities):
# Find the index of the desired metal in the input lists
metal_index = metal_prices.index(metal_name)
# Extract relevant values for the selected metal
metal_price = int(metal_prices[metal_index +1])
metal_density = float(metal_densities[metal_index +1].split('$')[1])
metal_resistivity = float(metal_resistivities[metal_index +1][1:])
# Constants for calculations
radius =0.5 # inches
length_miles =100
inches_per_mile =63360
pi =3.1415
# Calculate Weight
volume = pi *(radius **2)* length_miles * inches_per_mile
weight = volume * metal_density
# Calculate Price
price = weight * metal_price
# Calculate Resistivity
cross_sectional_area = pi *(radius **2)
resistivity = metal_resistivity * length_miles / cross_sectional_area
# Output results
print(f"OUTPUT {metal_name} Weight {weight:.3f}")
print(f"OUTPUT {metal_name} Price {price:.3f}")
print(f"OUTPUT {metal_name} Resistivity {resistivity:.3f}")
# Example input
metal_name_input = "METAL > Copper"
metal_prices_input = "PRICES > Copper 10 Aluminum 1000 Silver 105"
metal_densities_input = "DENSITIES > Silver$6.064SCopper$5.184SAluminum$1.561"
metal_resistivities_input = "RESISTS > Aluminum 1.04Silver0.63Copper0.66"
# Parse inputs and call the function
metal_name = metal_name_input.split('>')[1].strip()
metal_prices = metal_prices_input.split('>')[1].split()
metal_densities = metal_densities_input.split('>')[1].split('S')
metal_resistivities = metal_resistivities_input.split('>')[1].split()
calculate_properties(metal_name, metal_prices, metal_densities, metal_resistivities) The code is saying could not convert the string to a float

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Real Time Database Systems Architecture And Techniques

Authors: Kam-Yiu Lam ,Tei-Wei Kuo

1st Edition

1475784023, 978-1475784022

More Books

Students also viewed these Databases questions