121k views
5 votes
In Python!!

1. Correcting string errors
It's easy to make errors when you're trying to type strings quickly.
Don't forget to use quotes! Without quotes, you'll get a name error.
owner = DataCamp
Use the same type of quotation mark. If you start with a single quote, and end with a double quote, you'll get a syntax error.
fur_color = "blonde'
Someone at the police station made an error when filling out the final lines of Bayes' Missing Puppy Report. In this exercise, you will correct the errors.
# One or more of the following lines contains an error
# Correct it so that it runs without producing syntax errors
birthday = "2017-07-14'
case_id = 'DATACAMP!123-456?
2. Load a DataFrame
A ransom note was left at the scene of Bayes' kidnapping. Eventually, we'll want to analyze the frequency with which each letter occurs in the note, to help us identify the kidnapper. For now, we just need to load the data from ransom.csv into Python.
We'll load the data into a DataFrame, a special data type from the pandas module. It represents spreadsheet-like data (something with rows and columns).
We can create a DataFrame from a CSV (comma-separated value) file by using the function pd.read_csv.
# Import pandas
import pandas as pd
# Load the 'ransom.csv' into a DataFrame
r = ___.___('___')
# Display DataFrae
print(r)
3. Correcting a function error
The code in the script editor should plot information from the DataFrame that we loaded in the previous exercise.
However, there is an error in function syntax. Remember that common function errors include:
Forgetting closing parenthesis
Forgetting commas between each argument
Note that all arguments to the functions are correct. The problem is in the function syntax.
# One or more of the following lines contains an error
# Correct it so that it runs without producing syntax errors
# Plot a graph
plt.plot(x_values y_values)
# Display the graph
plt.show()
4. Snooping for suspects
We need to narrow down the list of suspects for the kidnapping of Bayes. Once we have a list of suspects, we'll ask them for writing samples and compare them to the ransom note.
A witness to the crime noticed a green truck leaving the scene of the crime whose license plate began with 'FRQ'. We'll use this information to search for some suspects.
As a detective, you have access to a special function called lookup_plate.
lookup_plate accepts one positional argument: A string representing a license plate.
# Define plate to represent a plate beginning with FRQ
# Use * to represent the missing four letters
____ = ____
Please help out~~~

User Mikki
by
4.8k points

1 Answer

8 votes

Answer:

Following are the solution to the given points:

Step-by-step explanation:

For point 1:

birthday = "2017-07-14" # defining a string variable birthday that string value

case_id = 'DATACAMP!123-456?' #defining a variable case_id that stores the string value

In this, two variable "birthday and case_id" is defined, that holds the string value. In the first variable, it uses the hyphen sign to hold the date value as a string. In the second variable, it uses a single quoit to store string value.

For point 2:

import pandas as pd # using import package to import pandas

r = pd.read_csv('ransom.csv')# defining r variable that uses pandas to Load the 'ransom.csv' file

print(r)#use print method to print r value

In this code, a pandas package is imported, and in the next step r variable is defined that uses the read method to hold the csv file , and the print method to print r value.

For point 3:

plt.plot(x_values, y_values) # Plot method to hold parameters values

plt.show()#calling the show method

In this code, the plot method is used, which accepts two-parameter to store its value into plt, and in the next step, it uses the show method.

For point 4:

# Defining a plate variable to represents the plate that starts with FRQ

# Using the * to represent the four missing letter

plate = lookup_plate('FRQ*)

User Rafael Lima
by
4.7k points