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

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

### 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 1 out of 20 pages

OR

OR

## Reviews( 0 )

### \$9.00

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

OR

91
0

### Document information

Connected school, study & course

Oct 02, 2022

Number of pages

20

Written in

#### Seller

##### QuizMaster

Member since 4 years

1085 Documents Sold

This document has been written for:

Oct 02, 2022

0

Views

91

## THE BEST STUDY GUIDES

Avoid resits and achieve higher grades with the best study guides, textbook notes, and class notes written by your fellow students

#### Avoid examination resits

Your fellow students know the appropriate material to use to deliver high quality content. With this great service and assistance from fellow students, you can become well prepared and avoid having to resits exams.

Your fellow student knows the best materials to research on and use. This guarantee you the best grades in your examination. Your fellow students use high quality materials, textbooks and notes to ensure high quality

Get paid by selling your notes and study materials to other students. Earn alot of cash and help other students in study by providing them with appropriate and high quality study materials.

\$9.00