-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextraHW.txt
63 lines (46 loc) · 3.09 KB
/
extraHW.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Extra Homework – Conversion Calculator
Write a script or notebook that converts a given value from its original unit to a different unit
You can either do the work in a new Jupyter Notebook or write a script.
In today's folder, there is a file called conversionMeasures.csv. It contains lines of data. Each line has three pieces of data, separated by commas: unit 1, conversion factor, unit 2.
The conversion equation for all of these lines is unit 1 x conversion factor = unit 2.
Your script should be able to convert the following test samples:
test_unit = "pint"
test_value = 2.5
final_unit = "mL"
test_unit = "cubic foot"
test_value = 30
final_unit = "liter"
test_unit = "slug"
test_value = "4.8" Yes, you should write your code to handle values that are entered as strings
final_unit = "pound"
Your script should:
• store the conversion data from the csv file in some object (list of lists, dictionary of dictionaries, etc.)
• provide a way to find the correct conversion factor from your data object
• include a function to convert between units
• print out a full sentence response with the final answer
• anticipate some errors (see below)
• run your script on the provided test examples
Errors to anticipate:
1. Someone might give the initial value as a string instead of a float/integer.
2. Someone might request a final unit that is not in your data – your script should print out an error message. Here’s a sample to test for this error:
test_unit = "slug"
test_value = 27.0
final_unit = "snail"
Tips:
• You might write out the steps you need to complete each task before you start coding
• Take it one step at a time
• If you are stuck, there is another version of this document that contains more detailed steps (thursdayHW-Help)
IF YOU ARE USING GOOGLE COLAB ONLY:
To upload the csv file, you will need to run a cell at the top of your notebook that says:
!wget https://raw.githubusercontent.com/aGitHasNoName/pythonBootcamp_3Day/main/conversionMeasures.csv
You can just copy and paste that line into a new code cell.
BONUS CHALLENGES
1. Someone might give a test or final unit that has different capitalization than how it is presented in the csv file. Edit your script so that it can still process this sample:
test_unit = "KM/H"
test_value = 8.4
final_unit = m/Sec
2. In the csv file, not all the units are included on both sides of the conversion factor. Someone might give you a test unit from the right side of the factor and ask you to convert it to the unit on the left side, which would require division instead of multiplication. Edit your script so that it can process this sample:
test_unit = "ergs"
test_value = 8.4
final_unit = "joule"
3. Advanced Challenge: there’s a function called input() that can collect data from the user of your script in real time. Here’s a link to a website that works through the input() function: https://datatofish.com/input-function-python/. You might find other helpful resources online as well. Try to use the input() function to collect the test_unit, test_value, and final_unit values from the user rather than having to hard code them into the script.