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

Reviews( 0 )

$9.00

Add to cart

Instant download

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

OR

GET ASSIGNMENT HELP
93
0

Document information


Connected school, study & course


About the document


Uploaded On

Oct 02, 2022

Number of pages

20

Written in

Seller


seller-icon
QuizMaster

Member since 4 years

1086 Documents Sold


Additional information

This document has been written for:

Uploaded

Oct 02, 2022

Downloads

 0

Views

 93

Document Keyword Tags

Recommended For You

What is Browsegrades

In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.

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 © Browsegrades · High quality services·