Question
Please write the python functions

Problem: Electric wire (Figure is a cylindrical conductor covered by an insulating material. Figure 2 shows the structure ofa single conductor. The resistance of a piece ofwire is given by the formula: A d where ρ is the resistivity of the conductor, and I (in meter), A, and d (in meter) are the length, cross-sectional area, and diameter of the wire. The wire diameter, d, is commonly specified by the American Wire Gauge (AWG). Which is a positive integer eenic wire igure 1 Cyfril n.The diameter d (in mm) at an AWG n wire is given by the formula d 0.127 x 9279-mm Materials such as copper and aluminum are known for their low levels A Single Conductor of resistivity thus allowing electrical current to easily flow through them making these materials ideal for making electrical wires and cables. Silver and gold have very low resistivity values, but for obvious reasons are more expensive to turn into electrical wires. The resistivity p value vary depends on the wire material type as follows: igure 2 A singecour . The resistivity of copper is l.678X10a Ω m. - The resistivity of aluminum is 2.82 X 10 2m. The resistivity of gold is 2 .44 X 104 Ω m. Write a python program that reads from a file some clectrical wire information (see sample input file in figure 3). For each wire, the program computes the resistance R based on its material, wire gauge and length values. Your program should validate the file records as follows Accepts positive wire gauge as integers n generates a positive random integer S40. Such a record has to be counted as illegal record for statistical purposes Accepts standard wire length in meter, L E [50, 200]. Any invalid length has to be ignored and the wire record is considered as illegal record. Allows copper, aluminum and gold materials only. For any other types, the program ignores the record and count it as illegal record. 40. Otherwise, it neglects the incorrect value and - The following figure 4 shows a sample output for the given sample input in figure 3. Page 2 of 4
35 100 copper Wire Wire Resistance 28 160 aluminum 15 110 copper 6 170 aluminum 40 95 aluminum no. gauge ength material COH) 100. 160.luminum 1.748E+01 11. Copper 1.119E+00 17. Aluminum 3.604E-01 95.0 200.0 Aluminum 4.240E-01 65.0 150.Copper 5.93SE-02 180. Gold 135.0 180. Copper 7.122E-02 280.0 luminum 5.434E+00 85.0 190. Coper 3.022E-01 5e.e 0.0 120.0 190.0 Copper e Copper 1.050E+02 2 23 3 15 200 aluminum 9 16 aluminum 27 45 gold 30 100 silver 39 65 gold 1150 copper 20 400 aluminum 40 180 gold 5 135 gold 50 180 copper 17 200 aluminum 7 85 copper 7 190 copper 19 50 copper 30 70 aluminum Sa 120 gold 21 190 copper 5 40 Aluminum 5.347E 02 2.510E 02 8.766E+02 7 39 9 40 10 5 .964E-01 12 17 13 7 14 7 15 19 16 30 Copper 1.352E-01 Copper 1.285E 80 Aluminum 3.876E+01 7.018E-01 7.767E 00 18 21 Total records: 22 Incorrect records: 8 corresponds to 36.36% of the records Figure 3 a sample inpur file of aluminum wires 27.27% Figure 4 A sample outpu a. main): the main function open an input file. It reads and validates each record, as explained earlier, and counts number of illegal records. For invalid wire gauge values, the program count it as illegal record and then generates a random positive integer n S 40 to compute the diameter for such a record to make it valid. Then, the main function computes the resistance value in OHM using different functions based on the wires material type. After all records are read, statistical information are computed including: total number of records in the input file, total number of illegal (invalid) records, and percentage of aluminum wires records in the input file. Obtained results should be displayed on the screen only as shown in figure 4 above. The main function has to call each of these functions appropriately printHeader. copperWireResistance0. gold WireResistance and aluminumWireResistance0 Notice:your program has to through suitable exceptions to handle Imputoutput errors andvalue error in the main function. b. printHeader: to display the table header of the output as shown in figure 4. This function does not return any value Page 3 of 4
c. diameter(wireGauge): accepts the wire gauge as a parameter and returns the corresponding wire diameter in meter. d. copperWireResistance (length, wireGuage): this function accepts the length and the wire gauge of a piece of copper wire and return the resistance R of that wire. This function calls diameter0 to computes the diameter of a copper wire in meter c. goldWireResistance (length, wireGuage): this function accepts the len gth and the wire gauge of a picce of gold wire and return the resistance R of that wire. This function calls diameterO to computes the diameter of a gold wire in meter. f. aluminum WireResistance (length, wireGuage): this function accepts the length and the wire gauge of a piece of aluminum wire and return the resistance R of that wire. This function calls diameter0 to computes the diameter of an aluminum wire in meter.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

import random
import math

def printHeader():
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print("Wire     Wire     Wire      Wire          Resistance")
    print(" no.     gauge    length    material       (OHM)")
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    
def diameter(wireGauge):
    d=0.127*math.pow(92,((36-wireGauge))/39)
    d=d/1000
    return d
def copperWireResistance(length,wireGauge):
    p=1.678E-8
    d=diameter(wireGauge)
    R=(4*p*length)/(math.pi*d*d)
    return "%10.3E"%(R)
    
def goldWireResistance(length,wireGauge):
    p=2.44E-8
    d=diameter(wireGauge)
    R=(4*p*length)/(math.pi*d*d)
    return "%10.3E"%(R)

def aluminumWireResistance(length,wireGauge):
    p=2.82E-8
    d=diameter(wireGauge)
    R=(4*p*length)/(math.pi*d*d)
    return "%10.3E"%(R)
#print(copperWireResistance(100,35))
#print(aluminiumWireResistance(160,23))

def main():
    printHeader()
    fh=open("SampleInput.txt",'r')
    contents=fh.readlines()
    illegal=0
    total=0
    count=0
    aluminum_total=0
    for line in contents:
        #print(len(list(line.split(' '))))
        gauge,length,material=line.rstrip().split(' ')
        length=float(length)
        total+=1
        try:
            if not(int(gauge)>0 and int(gauge)<=40):
                raise ValueError
        except ValueError:
            gauge=random.randint(1,40)
            illegal+=1
           
        if not(length>=50 and length<=200):
            illegal+=1
            continue
            
        if material=='gold':
            count+=1
            R=goldWireResistance(length,int(gauge))
            print(count,"\t",gauge,"\t ",length,"    Gold \t ",R)
        elif material=='copper':
            count+=1
            R=copperWireResistance(length,int(gauge))
            print(count,"\t",gauge,"\t ",length,"    Copper\t ",R)
        elif material=='aluminum':
            count+=1
            aluminum_total+=1
            R=aluminumWireResistance(length,int(gauge))
            print(count,"\t",gauge,"\t ",length,"    Aluminum\t ",R)
        else:
            illegal+=1
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print("Total records:",total)  
    incorrect=illegal*100/total
    print("Incorrect records:",illegal,"corresponds to "+str(round(incorrect,2))+"% of the records")
    alu_per=aluminum_total*100/total
    print("Percentage of aluminum wires "+str(round(alu_per,2))+"%")
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
            
main()       
        

Note: Sample input file should have values separated by a single space.

Sample Input:

SampleInput.txt

35 100 copper
-28 160 aluminum
15 110 copper
6 170 aluminum
40 95 aluminum
- 200 aluminum
9 16 aluminum
27 45 gold
30 100 silver
39 65 gold
1 150 copper
20 400 aluminum
40 180 gold
5 135 gold
50 180 copper
17 200 aluminum
7 85 copper
7 190 copper
19 50 copper
30 70 aluminum
5a 120 gold
21 190 copper

Output:

Add a comment
Know the answer?
Add Answer to:
Please write the python functions Problem: Electric wire (Figure is a cylindrical conductor covered by an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  •   Need this question answered in python. Science P5.35 Electric wire, like that in the photo, is...

      Need this question answered in python. Science P5.35 Electric wire, like that in the photo, is a cylindrical conductor covered by an insulat- ing material. The resistance of a piece of wire is given by the formula where p is the resistivity of the conductor, and L, A, and d are the length, cross- sectional area, and diameter of the wire. The resistivity of copper is 1.678 × 10-8 Ω m. The wire diameter, d, is commonly specified by the...

  • You want to produce three 1.00-mmmm-diameter cylindrical wires, each with a resistance of 2.00 ΩΩ at...

    You want to produce three 1.00-mmmm-diameter cylindrical wires, each with a resistance of 2.00 ΩΩ at room temperature. One wire is gold, one is copper, and one is aluminum. Refer to Table 25.1 in the textbook for the resistivity values. C.) What will be the length of the aluminum wire? Include units D.) Gold has a density of 1.93 ×× 1044 kg/m3kg/m3. What will be the mass of the gold wire? Include Units E.) If gold is currently worth $$40...

  • 1 Rev You want to produce three 1.00-mm-diameter cylindrical wires, each with a resistance of 5.00...

    1 Rev You want to produce three 1.00-mm-diameter cylindrical wires, each with a resistance of 5.00 N at room temperature, One wire is gold, one is copper, and one is aluminum. Refer to Table 25. 1 in the textbook for the resistivity values. Part A What will be the length of the gold wire? Express your answer with the appropriate units. L 161 m Correct Part B What will be the length of the copper wire? Express your answer with...

  • please solve the problem

    Determine the overall resistance of a 100-meter length of 14 AWA (0.163 cm diameter) wire made of the following materials.a. copper (resistivity = 1.67x10-8 O•m)b. silver (resistivity = 1.59x10-8 O•m)c. aluminum (resistivity = 2.65x10-8 O•m)d. iron (resistivity = 9.71x10-8 O•m)

  • Two square wires are composed differently, see the figure of their cross-sections. Wire 1 is a...

    Two square wires are composed differently, see the figure of their cross-sections. Wire 1 is a square wire of material A but with a circular center of material C. The diameter of the circular inside is equal to the length of side of the square. The second square wire has the same cross-sectional area as the first but is entirely comprised of material A. Both wires are the same length and setup to have the same temperature difference maintained between...

  • problem A wire 4.00 m long and 6.00 mm in diameter has a resistance of 15.0...

    problem A wire 4.00 m long and 6.00 mm in diameter has a resistance of 15.0 m2. A potential difference of 22.0 v is applied between the ends Resistivity, p Temperature Coefficient of Resistivity, a(K-1) Material (2 m) Typical Metals 41 x 10-3 Silver 1.62 x 10 43 x 10-3 1.69 x 10 Copper 40 x 10-3 2.35 x 10-8 Gold 4.4 x 10 2.75 x 10 Aluminum 4.82 x 10-s 0.002 x 10-3 Manganin 4.5 x 10-3 5.25 x...

  • 1. A ductile metal wire has resistance R. Then the wire is stretched to three times...

    1. A ductile metal wire has resistance R. Then the wire is stretched to three times its original(poin) length. The stretching shrinks the diameter of the wire, but does not affect its density or resistivity. What is the resistance of the stretched wire? O3R 2. A current of 1.50 A flows through the leads of an electric appliance. How long does it take for (1 point) 7.50 C of charge to pass through the leads? 0 2.00s 11.0 s 6.00s...

  • It is possible to crudely determine the resistivity of a material using the following equipment and...

    It is possible to crudely determine the resistivity of a material using the following equipment and materials. Five coils of wire all made of the same unknown metal can be produced with characteristics shown in the table below. In addition to each coil being made of the same metal, each coil is wound using 10 meters of wire. The difference between each coil is the diameter of wire. Coil characteristics Length Coil Number Gauge (AWG) Diameter (mm) (m) 10 2.58826...

  • hey, this is a filei/o homework. um please show me how to do this (im using...

    hey, this is a filei/o homework. um please show me how to do this (im using ONLY arraylist for the first part so please continue on that) i have put my work please fix some mistakes and continue on it. the file is named “tools.txt” its a text document file that i savedin the netbeansprojects file. um pleas euse netbeans and show me the output afterwards, make it simple and continue on what i have worked on whilw fixing some...

  • MATLAB question: I have written a code to solve for a metals resitance. Here is the...

    MATLAB question: I have written a code to solve for a metals resitance. Here is the problem statement: Part 1 (Algorithms) – due Friday: Think about how you might solve the problem of calculating the resistance of a given group of metals depending on the type of metal, the length of the wire and the area of the wire (if given the diameter only – so you must calculate the area). Write instructions (an algorithm) for a script that behaves...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT