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

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

The preview shows page 3 - 4 out of 17 pages.
hw02September 16, 20181Homework 2: Arrays and TablesRecommended Reading: *Data Types*Sequences*Tables.Please complete this notebook by filling in the cells provided. Before you begin, execute thefollowing cell to load the provided tests. Each time you start your server, you will need to executethis cell again to load the tests.Homework 2 is due Thursday, 9/6 at 11:59pm.Start early so that you can come to officehours if you’re stuck. Check the website for the office hours schedule. You will receive an earlysubmission bonus point if you turn in your final submission by Wednesday, 9/5 at 11:59pm. Latework will not be accepted as per the policies of this course.Throughout this homework and all future ones, please be sure to not re-assign variablesthroughout the notebook! For example, if you usemax_temperaturein your answer to one ques-tion, do not reassign it later on.In [1]:# Don't change this cell; just run it.importnumpyasnpfromdatascienceimport*fromclient.api.notebookimportNotebookok=Notebook('hw02.ok')_=ok.auth(inline=True)=====================================================================Assignment: Homework 2: Arrays and TablesOK, version v1.12.5=====================================================================Successfully logged in as [email protected]Important: In this homework, theoktests will tell you whether your answer is correct, ex-cept for Parts 4, 5 & 6. In future homework assignments, correctness tests will typically not beprovided.In [ ]:1
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).

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 17 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
N/A
Tags
World population, 3rd millennium, Test Summary

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture