Question

In: Computer Science

1) answer parts a through d using pythons new f string formating. All parts have examples...

1) answer parts a through d using pythons new f string formating. All parts have examples of what is expected to be returned

a) Write a function with prototype “def fstring1(a,b,c,d,e):” whose body simply returns a single f-string such that print(fstring1(13,12,11,10,9)) followed by print(fstring1(666,666,666,666,666)) generates exactly

val1= 13, val2=0012, val3= b, val4=0x000A, val5=9. Done!

val1= 666, val2=0666, val3= 29a, val4=0x029A, val5=666. Done!

Pay close attention to the number of spaces, leading zeros, capitalization when in hexidecimal, etc

b) Write a function with prototype “def fstring2(a,b,c,d,e):” whose body simply returns a single f-string such that print(fstring2(13,12,11,10,9)) followed by print(fstring2(666,666,666,666,666)) generates exactly

val1= 13.0, val2=0012.0, val3= 1.1e+01, val4=001.0e+01 val5=9.0E+00. Done!

val1= 666.0, val2=0666.0, val3= 6.7e+02, val4=006.7e+02 val5=6.7E+02. Done!

Pay close attention to the number of spaces, leading zeros, capitalization (of “E”), etc.

c) Write a function with prototype “def fstring3(a,b,c,d):” whose body simply returns a single f-string such that print(fstring3("Ho","Ho", "Ho", "way to go!")) followed by print(fstring3("Eeny", "meeny", "miny", "moe")) generates exactly

val1=Ho , val2= Ho , val3= Ho, val4=way to go!. Done!

val1=Eeny , val2= meeny , val3= miny, val4=moe. Done!

Pay close attention to the field widths and justification

d) Write test code for the above functions that tests using the given strings.

Solutions

Expert Solution

Solution: Required code for the 4 parts have been given below along with the output. Comments have been placed to depict the part.

#part a
def fstring1(a,b,c,d,e):
    return(f"val1={a}, val2={b:04}, val3={c:x},val4=0x{d:04X},val5={e}. Done!" )

#part b
def fstring2(a,b,c,d,e):
    return(f"val1={a:.1f}, val2={b:06.1f}, val3={c:.1e},val4={d:09.1e},val5={e:.1E}. Done!" )

#part c
def fstring3(a,b,c,d):
    x = len(a) + 1
    y = len(b) + 2
    z = len(c) + 1
    return(f"val1={a:<{x}}, val2={b:^{y}}, val3={c:>{z}}, val4={d}. Done!")

#part d
if __name__ == "__main__":
    print(fstring1(13,12,11,10,9))
    print(fstring1(666,666,666,666,666))

    print(fstring2(13,12,11,10,9))
    print(fstring2(666,666,666,666,666))

    print(fstring3("Ho","Ho", "Ho", "way to go!"))
    print(fstring3("Eeny", "meeny", "miny", "moe"))

output

val1=13, val2=0012, val3=b,val4=0x000A,val5=9. Done!
val1=666, val2=0666, val3=29a,val4=0x029A,val5=666. Done!

val1=13.0, val2=0012.0, val3=1.1e+01,val4=001.0e+01,val5=9.0E+00. Done!
val1=666.0, val2=0666.0, val3=6.7e+02,val4=006.7e+02,val5=6.7E+02. Done!

val1=Ho , val2= Ho , val3= Ho, val4=way to go!. Done!
val1=Eeny , val2= meeny , val3= miny, val4=moe. Done!


Related Solutions

this as a whole question 1, answer all parts please a)Show that the derivative of f(x)...
this as a whole question 1, answer all parts please a)Show that the derivative of f(x) = 6+4x^2 is f(x)'=8x by using the definition of the derivative as the limit of a difference quotient. b)If the area A = s^2 of an expanding square is increasing at the constant rate of 4 square inches per second, how fast is the length s of the sides increasing when the area is 16 square inches? c)Find the intervals where the graph of...
Answer ALL parts. (a) The reaction B + C → D just becomes spontaneous at a...
Answer ALL parts. (a) The reaction B + C → D just becomes spontaneous at a temperature of 78.1 °C. When the temperature is increased to 220 °C: (i) Calculate Gibbs free energy (ii) Calculate equilibrium constant (iii) State whether the products or reactants are favoured at this temperature and explain your reasoning (iv) State the assumptions associated with your calculations. Useful data for this question: ΔSreaction (B + C → D) = 259.4 J K–1 mol–
1. Answer any three of the following parts (a) - (d). (a) The hydrolysis of a...
1. Answer any three of the following parts (a) - (d). (a) The hydrolysis of a compound A-B in a dilute aqueous solution proceeds in one elementary step: A-B + H2O → A-OH + H-B (i) Describe the order of this reaction. (ii) Outline the differential and the integrated rate laws for this reaction. (iii) Calculate the reaction rate constant if the concentration of A-B at time 10 s was 0.1 mol L-1 and at time 1000 s was 0.001...
Please, Answer all parts( a,b,c,d) in Question 1 and step by step. Also, by word document...
Please, Answer all parts( a,b,c,d) in Question 1 and step by step. Also, by word document or by keyboard 1. Given below are a set of foreign exchange quotes for several currencies against the Australian dollar as of August 5, 2020. Australian Dollar Exchange Rates Currency Sell/buy US, dollar 0.7143/0.7143 UK, pound 0.5458/0.5459 China, yuan Renminbi 4.9872/4.9907 Hong Kong, dollar   5.5349/5.5364 India, rupee 53.572/53.669 Japan, yen   75.70/75.70 Malaysia, ringgit 3.0104/3.0139 Philippines, peso   34.953/35.135 South Africa, rand 12.2272/12. 2340 Switzerland, franc  ...
please answer all qustions and all parts and make sure you have the right answers. 1....
please answer all qustions and all parts and make sure you have the right answers. 1. An electric field is given by Ex = 3.5x3 kN/C. Find the potential difference between the points on the x axis at x = 1 m and x = 3 m. ..... kV --------------------------------- 2. (a) Find the maximum net charge that can be placed on a spherical conductor of radius 12 cm before dielectric breakdown of the air occurs. .... µC (b) What...
Please answer all the parts of this question Please answer all the parts of this question...
Please answer all the parts of this question Please answer all the parts of this question Question: a) Where is the flow accelerating in the control volume? b) Will the pressure be greater or less than hydrostatic in a region of accelerating flow? c) Is the hydrostatic estimate of force on the gate; larger, smaller, or the same, as that obtained from the Momentum Equation? Explain. d) Where does the change in flow momentum go in this control volume? Explain.
This Question has 6 parts a) to f): Answer all of them below: A local wine...
This Question has 6 parts a) to f): Answer all of them below: A local wine manufacturer in Pennsylvania has designed a new package for its existing product and wants to test its effectiveness using a field experiment. The manufacturer knows that for the old package, the average sales per day in State College is $4,000 and the average sales per day in Lancaster is $6,000. The manufacturer launched field experiments in wine shops at two areas: State College and...
Please, Answer all parts( a,b,c,d,e) in Question 1 and step by step. Also, by word document...
Please, Answer all parts( a,b,c,d,e) in Question 1 and step by step. Also, by word document or by keyboard 2. The following data are taken from the financial market pages of an Australian newspaper. Forward Margins Forward Contract Forward Margins (Buy A$/Sell A$) 1 month 0/1 2 month 1/2 3 month 1/3 6 month 2/4 1 year 0/1 2 year -16/-8 3 year -51/-11 The data under the “Forward Margins” column represent the forward contracts for the US dollar with...
For the given functions f and​ g, complete parts​ (a)-(h). For parts​ (a)-(d), also find the...
For the given functions f and​ g, complete parts​ (a)-(h). For parts​ (a)-(d), also find the domain. f left parenthesis x right parenthesis equals StartFraction 7 x plus 9 Over 9 x minus 7 EndFractionf(x)=7x+99x−7​; g left parenthesis x right parenthesis equals StartFraction 9 x Over 9 x minus 7 EndFractiong(x)=9x9x−7​(a) Find ​(fplus+​g)(x). ​(fplus+​g)(x)equals=nothing ​(Simplify your​ answer.)What is the domain of fplus+​g? Select the correct choice below​ and, if​ necessary, fill in the answer box to complete your choice. A.The...
Answer the following parts for question 1: a) Do all businesses have a supply chain yes/no...
Answer the following parts for question 1: a) Do all businesses have a supply chain yes/no b) Are all parts of the supply chain for a business within that same business yes/no c) Does a business have full control over all aspects of its supply chain yes/no d) What role can an Accounting information system play in enhancing the supply chain. (two sentences) e) What does supply chain management involve and why is it important to manage the supply chain...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT