diff --git a/Day 1 homework - Xuanyi Wang (Sloetjes).md b/Day 1 homework - Xuanyi Wang (Sloetjes).md index 87868fb..28122c2 100644 --- a/Day 1 homework - Xuanyi Wang (Sloetjes).md +++ b/Day 1 homework - Xuanyi Wang (Sloetjes).md @@ -1,13 +1,13 @@ # Xuanyi Wang\_Day-1\_Homework\_03/30/23 -### 1. What is the name of the international standard for floating-point representation? +#### 1. What is the name of the international standard for floating-point representation? **IEEE 754** -### 2. How many bits are the floating point numbers defined by that standard allowed to be? +#### 2. How many bits are the floating point numbers defined by that standard allowed to be? ####Single-precision format (32-bits) @@ -23,7 +23,7 @@ Double-precision floating-point numbers are represented using 64 bits, with 1 bi * However, these formats are less commonly used than the single-precision and double-precision formats. -### 3. Does your computer support all those formats? Can you think of an easy way to check with only one line of Python? +#### 3. Does your computer support all those formats? Can you think of an easy way to check with only one line of Python? @@ -33,7 +33,7 @@ import platform platform.architecture()[0] ``` -### 4. Why doesn't this code give the same answers to the two multiplications? +#### 4. Why doesn't this code give the same answers to the two multiplications? ``` mport pandas as pd import numpy as np @@ -60,7 +60,7 @@ print(df) `num1` and `num2` are both 64-bit integers, which means that ` num1 * num2` is performed using 64-bit integer arithmetic. However,`df[‘Number1’] ` and `df[‘Number2’] ` are Pandas Series objects and they are 64-bit floating point numbers so `df[‘Number1’] * df[‘Number2’] ` is performed using floating-point arithmetic which involves approximations and rounding errors. -### 1. You can use sys.getsizeof to see how large a Python object is. Does the size of a Python floating-point number change as it gets larger? Why or why not? +#### 1. You can use sys.getsizeof to see how large a Python object is. Does the size of a Python floating-point number change as it gets larger? Why or why not? **The size of a Python floating-point number does not change as it gets larger.** @@ -71,14 +71,14 @@ Regardless of the magnitude of the float, the number of bytes used to represent However, it's worth noting that as the magnitude of a floating-point number grows larger, the number of significant digits it can represent decreases. This is due to the limited precision of floating-point arithmetic, and can result in rounding errors when performing calculations with very large or very small floating-point numbers. -### 2. We already know that the precision of floating-point numbers decreases as their magnitude increases. Using Pandas, create a dataframe representing a large amount of US Dollars. What is the smallest number of dollars where adding one cent begins to yield wrong results? +#### 2. We already know that the precision of floating-point numbers decreases as their magnitude increases. Using Pandas, create a dataframe representing a large amount of US Dollars. What is the smallest number of dollars where adding one cent begins to yield wrong results? Assuming double-precision floating-point numbers (64 bits), the smallest number of dollars that can be represented is $0.01 divided by 2 to the power of 52 (the number of bits used to represent the fraction part of a double-precision number). This equals approximately **$0.0000000000002384**. Therefore, any calculation involving adding 0.01 to a dollar amount smaller than **$0.0000000000002384** may yield wrong results due to the limited precision of floating-point arithmetic. -### 3. Name three practical differences between Python strings and bytes. Using sys.getsizeof, see how the sizes may be different. Do emoji change this answer? +#### 3. Name three practical differences between Python strings and bytes. Using sys.getsizeof, see how the sizes may be different. Do emoji change this answer? ** Encoding**: Python strings are used to represent text data, while bytes are used to represent binary data. Strings are typically encoded using a character encoding such as UTF-8 or ASCII, which maps each character to a sequence of bytes, while bytes represent raw binary data that may not necessarily correspond to any particular character encoding. @@ -116,7 +116,7 @@ Size of s2: 104 ``` -### 4. Given this sample CSV file (tomato_sales.csv): +#### 4. Given this sample CSV file (tomato_sales.csv): ``` Store,Region,Tomato_Sales Store1,East,300