Programming  >  QUESTIONS & ANSWERS  >  DATA MISC Homework 2: Arrays and Tables | University of California, Berkeley (All)

DATA MISC Homework 2: Arrays and Tables | University of California, Berkeley

Document Content and Description Below

University of California, Berkeley DATA MISC Homework 2: Arrays and Tables¶ Recommended Reading: • Data Types • Sequences • Tables. 1. Creating Arrays¶ Question 1. Make an arra ... y called weird_numbers containing the following numbers (in the given order): 1. -2 2. the sine of 1.2 3. 3 4. 5 to the power of the cosine of 1.2 Hint: sin and cos are functions in the math module. In [2]: # Our solution involved one extra line of code before creating # weird_numbers. import math as m weird_numbers = make_array(-2, m.sin(1.2), 3, 5**(m.cos(1.2))) weird_numbers Question 2. Make an array called book_title_words containing the following three strings: "Eats", "Shoots", and "and Leaves". Strings have a method called join. join takes one argument, an array of strings. It returns a single string. Specifically, the value of a_string.join(an_array) is a single string that's the concatenation ("putting together") of all the strings in an_array, except a_string is inserted in between each string. Question 3. Use the array book_title_words and the method join to make two strings: 1. "Eats, Shoots, and Leaves" (call this one with_commas) 2. "Eats Shoots and Leaves" (call this one without_commas) Hint: If you're not sure what join does, first try just calling, for example, 2. Indexing Arrays¶ These exercises give you practice accessing individual elements of arrays. In Python (and in many programming languages), elements are accessed by index, so the first element is the element at index 0. Question 1. The cell below creates an array of some numbers. Set third_element to the third element of some_numbers Question 2. The next cell creates a table that displays some information about the elements of some_numbers and their order. Run the cell to see the partially-completed table, then fill in the missing information in the cell (the strings that are currently "???") to complete the table. Question 3. You'll sometimes want to find the last element of an array. Suppose an array has 142 elements. What is the index of its last element? Question 4. The cell below loads an array called president_birth_years. The last element in that array is the most recent birth year of any deceased president. Assign that year to most_recent_birth_year [Show More]

Last updated: 1 year ago

Preview 5 out of 20 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Loading document previews for DATA MISC Homework 2: Arrays and Tables | University of California, Berkeley

Loading document previews ...

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Reviews( 0 )

$6.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

209
0

Document information


Connected school, study & course


About the document


Uploaded On

Oct 01, 2022

Number of pages

20

Written in

All

Seller


Profile illustration for QuizMaster
QuizMaster

Member since 6 years

1196 Documents Sold

Reviews Received
185
56
29
11
17
Additional information

This document has been written for:

Uploaded

Oct 01, 2022

Downloads

 0

Views

 209


$6.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·