# hw02.pdf - hw02 September 16, 2018 1 Homework 2: Arrays and...

• Homework Help
• 17
• 100% (105) 105 out of 105 people found this document helpful

This preview shows page 1 - 4 out of 17 pages.

The preview shows page 3 - 4 out of 17 pages.
1.11. Creating ArraysQuestion 1.Make an array calledweird_numberscontaining the following numbers (in the givenorder):1. -22. the sine of 1.23. 34. 5 to the power of the cosine of 1.2Hint:sinandcosare functions in themathmodule.In [2]:# Our solution involved one extra line of code before creating# weird_numbers.importmathweird_numbers=make_array(-2, math.sin(1.2),3,5**(math.cos(1.2)))weird_numbersOut[2]:array([-2.,0.93203909,3.,1.79174913])In [3]:_=ok.grade('q1_1')~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Running tests---------------------------------------------------------------------Test summaryPassed: 1Failed: 0[ooooooooook] 100.0% passedQuestion 2.Make an array calledbook_title_wordscontaining the following three strings:"Eats", "Shoots", and "and Leaves".In [6]:book_title_words=make_array('Eats','Shoots','and Leaves')book_title_wordsOut[6]:array(['Eats','Shoots','and Leaves'], dtype='<U10')In [7]:_=ok.grade('q1_2')~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Running tests---------------------------------------------------------------------Test summaryPassed: 7Failed: 0[ooooooooook] 100.0% passed2
Question 3.Use the arraybook_title_wordsand the methodjointo make two strings:
1. "Eats, Shoots, and Leaves" (call this onewith_commas)2. "Eats Shoots and Leaves" (call this onewithout_commas)Hint:Ifyou’renotsurewhatjoindoes,firsttryjustcalling,forexample,"foo".join(book_title_words).

Course Hero member to access this document

Course Hero member to access this document

End of preview. Want to read all 17 pages?