Skip to content

Commit 90547b8

Browse files
authored
Merge pull request #108 from fhdsl/updating_format
Coursera formatting updates
2 parents 14ce2f3 + a2c644a commit 90547b8

12 files changed

+473
-270
lines changed

01-intro.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ This is not a comprehensive list!
9696

9797
- [Phind](https://www.phind.com/) is a AI-powered search engine designed specifically for developers asking technical questions. In addition to answering your coding question, it will provide links to the internet sources used to find the answer.
9898

99-
- [Poe](https://poe.com/) is Quora's platform that gives you access to multiple AI chatbots, including Sage, based on OpenAI's GPT-3.5 architecture; Claude, an AI natural language bot created by [Anthropic](https://www.anthropic.com); and ChatGPT.
99+
- [Poe](https://poe.com/) is Quora's platform that gives you access to multiple AI chatbots, including Sage, based on OpenAI's GPT-3.5 architecture; Claude, an AI natural language bot created by [Anthropic](https://www.anthropic.com); Llama 2, created by [Meta](https://ai.meta.com/llama/), and ChatGPT.
100100

101101
**IDE-based chatbots**
102102

@@ -158,4 +158,4 @@ Code in these boxes was written by AI.
158158

159159
## About This Book
160160

161-
We used AI bots (including ChatGPT, Bard, Sage, and Claude) to develop and write much of this course. We firmly believe this new technology can be used in ethical ways and we put into practice all the rules and suggestions offered over the following modules while we created this book.
161+
We used AI bots (including ChatGPT, Bard, Sage, and Claude) as part of the process of creating this book. The words are all original content, but we used AI bots to edit for grammar and tone. We firmly believe this new technology can be used in ethical ways and we put into practice all the rules and suggestions offered over the following modules while we created this book.

03-writing_code.Rmd

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -509,40 +509,6 @@ ottrpal::include_slide("https://docs.google.com/presentation/d/1MCNeSO4aOm1iESWD
509509
```
510510

511511

512-
513-
## Hands On Exercise
514-
515-
Now it’s your turn to try!
516-
517-
### Code
518-
519-
Here's the code you need for question #2.
520-
521-
```
522-
def calculate_average(numbers):
523-
total = 0
524-
for number in numbers:
525-
total += number
526-
average = total / len(numbers)
527-
return average
528-
529-
numbers = [1, 2, 3, 4, "5"]
530-
average = calculate_average(numbers)
531-
print("The average of the numbers is:", average)
532-
```
533-
534-
### Questions
535-
536-
1. Write a prompt to create a function that replaces all instances of the string "three" with the number 3, then create a prompt that allows you to modify the function so that "three", "Three", and "THREE" are all replaced with the number 3.
537-
538-
1. Write a query that helps you debug the code snippet from above.
539-
540-
1. Create a query that explains how to retrieve data from an online database. Don't forget to find out what the source of the code is.
541-
542-
1. Write a prompt to plan out a program that creates and plays a game of Rock, Paper, Scissors. You should create a multi-step plan as well as figure out what your first coding task should be.
543-
544-
1. Create a prompt that identifies the best coding language for the above game.
545-
546512
## Summary
547513

548514
* Coding has become an essential skill in today's world. AI can increase the efficiency of planning, writing, and debugging code, as well as make coding more accessible for beginners.

03-writing_code_activity.Rmd

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
3+
```{r, include = FALSE}
4+
ottrpal::set_knitr_image_path()
5+
```
6+
7+
# Writing Code: Hands-On Exercise
8+
9+
Now it’s your turn to try!
10+
11+
## Code
12+
13+
Here's the code you need for question #2.
14+
15+
```
16+
def calculate_average(numbers):
17+
total = 0
18+
for number in numbers:
19+
total += number
20+
average = total / len(numbers)
21+
return average
22+
23+
numbers = [1, 2, 3, 4, "5"]
24+
average = calculate_average(numbers)
25+
print("The average of the numbers is:", average)
26+
```
27+
28+
## Questions
29+
30+
1. Write a prompt to create a function that replaces all instances of the string "three" with the number 3, then create a prompt that allows you to modify the function so that "three", "Three", and "THREE" are all replaced with the number 3.
31+
32+
1. Write a query that helps you debug the code snippet from above.
33+
34+
1. Create a query that explains how to retrieve data from an online database. Don't forget to find out what the source of the code is.
35+
36+
1. Write a prompt to plan out a program that creates and plays a game of Rock, Paper, Scissors. You should create a multi-step plan as well as figure out what your first coding task should be.
37+
38+
1. Create a prompt that identifies the best coding language for the above game.
39+
40+
41+
42+
```{r}
43+
devtools::session_info()
44+
```
45+
46+

04-refactoring.Rmd

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -519,89 +519,6 @@ Because AI models are created by humans, they can be biased. This means they may
519519

520520
When using AI to refactor code, the code itself is often sent to an external service or platform for analysis and transformation. This can raise concerns about the security of the code, especially if it contains sensitive information such as trade secrets, proprietary algorithms, or personal data. If your code is sensitive, it's important to carefully vet any third-party AI tools or services used in the refactoring process.
521521

522-
## Hands-On Exercise
523-
524-
Now it's your turn to try.
525-
526-
### The Code
527-
528-
Let's say you are dusting off some code from your past (no judgment here). You were investigating tweets about [Mr. Trash Wheel](https://www.mrtrashwheel.com/), a beloved Baltimore-based contraption that filters trash out of the waterways.
529-
530-
**Note**: This code is just an example and was written strictly for educational purposes.
531-
532-
```{python eval = FALSE, python.reticulate = FALSE}
533-
import tweepy
534-
import pandas
535-
536-
# Enter your API keys and access tokens here
537-
consumer_key = 'your_consumer_key'
538-
consumer_secret = "your_consumer_secret"
539-
access_token = 'your_access_token'
540-
access_token_secret = 'your_access_token_secret'
541-
542-
# Authenticate with Twitter API
543-
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
544-
auth.set_access_token(access_token, access_token_secret)
545-
546-
# Search for tweets containing the search term
547-
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q="Mr. Trash Wheel", tweet_mode='extended').items(100)
548-
549-
# Create empty list to store tweet data
550-
date_data = []
551-
location_data = []
552-
text_data = []
553-
554-
def get_tweet_length(tweet):
555-
# Return the length of the tweet text
556-
return len(tweet.full_text)
557-
558-
# Loop through each tweet and extract desired data
559-
for tweet in tweets:
560-
date_info = {
561-
'date': tweet.created_at
562-
}
563-
date_data.append(date_info)
564-
565-
# Search for tweets containing the search term
566-
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q="Mr. Trash Wheel", tweet_mode='extended').items(100)
567-
568-
# Loop through each tweet and extract desired data
569-
for tweet in tweets:
570-
location_info = {
571-
'location': tweet.user.location
572-
}
573-
location_data.append(location_info)
574-
575-
# Search for tweets containing the search term
576-
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q='Mr. Trash Wheel', tweet_mode='extended').items(100)
577-
578-
# Loop through each tweet and extract desired data
579-
for tweet in tweets:
580-
text_info = {
581-
'text': tweet.full_text
582-
}
583-
text_data.append(text_info)
584-
585-
# Combine lists into a dictionary
586-
data = {'date': date_data,
587-
'location': location_data, 'text': text_data}
588-
589-
# Store results in pandas dataframe
590-
df = pandas.DataFrame(data)
591-
592-
# Print dataframe
593-
print(df)
594-
```
595-
596-
### Questions
597-
598-
1. Create an AI prompt that fixes any formatting issues with the code that would cause it not to run.
599-
600-
1. Devise an AI prompt that removes any dead code from your sample above. What gets removed?
601-
602-
1. Create a prompt that makes the code less repetitive, adhering to the DRY principle. What aspect of the code was repetitive?
603-
604-
1. Construct a prompt that makes the code more concise. What are some trade-offs that appear in this code between readability and brevity?
605522

606523
## Summary
607524

04-refactoring_activity.Rmd

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
2+
```{r, include = FALSE}
3+
# enable python code previews; must use python 3
4+
library(reticulate)
5+
use_python("/usr/bin/python3")
6+
7+
ottrpal::set_knitr_image_path()
8+
```
9+
10+
11+
# Refactoring Code: Hands-On Exercise
12+
13+
Now it's your turn to try.
14+
15+
## The Code
16+
17+
Let's say you are dusting off some code from your past (no judgment here). You were investigating tweets about [Mr. Trash Wheel](https://www.mrtrashwheel.com/), a beloved Baltimore-based contraption that filters trash out of the waterways.
18+
19+
**Note**: This code is just an example and was written strictly for educational purposes.
20+
21+
```{python eval = FALSE, python.reticulate = FALSE}
22+
import tweepy
23+
import pandas
24+
25+
# Enter your API keys and access tokens here
26+
consumer_key = 'your_consumer_key'
27+
consumer_secret = "your_consumer_secret"
28+
access_token = 'your_access_token'
29+
access_token_secret = 'your_access_token_secret'
30+
31+
# Authenticate with Twitter API
32+
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
33+
auth.set_access_token(access_token, access_token_secret)
34+
35+
# Search for tweets containing the search term
36+
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q="Mr. Trash Wheel", tweet_mode='extended').items(100)
37+
38+
# Create empty list to store tweet data
39+
date_data = []
40+
location_data = []
41+
text_data = []
42+
43+
def get_tweet_length(tweet):
44+
# Return the length of the tweet text
45+
return len(tweet.full_text)
46+
47+
# Loop through each tweet and extract desired data
48+
for tweet in tweets:
49+
date_info = {
50+
'date': tweet.created_at
51+
}
52+
date_data.append(date_info)
53+
54+
# Search for tweets containing the search term
55+
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q="Mr. Trash Wheel", tweet_mode='extended').items(100)
56+
57+
# Loop through each tweet and extract desired data
58+
for tweet in tweets:
59+
location_info = {
60+
'location': tweet.user.location
61+
}
62+
location_data.append(location_info)
63+
64+
# Search for tweets containing the search term
65+
tweets = tweepy.Cursor(tweepy.API(auth).search_tweets, q='Mr. Trash Wheel', tweet_mode='extended').items(100)
66+
67+
# Loop through each tweet and extract desired data
68+
for tweet in tweets:
69+
text_info = {
70+
'text': tweet.full_text
71+
}
72+
text_data.append(text_info)
73+
74+
# Combine lists into a dictionary
75+
data = {'date': date_data,
76+
'location': location_data, 'text': text_data}
77+
78+
# Store results in pandas dataframe
79+
df = pandas.DataFrame(data)
80+
81+
# Print dataframe
82+
print(df)
83+
```
84+
85+
## Questions
86+
87+
1. Create an AI prompt that fixes any formatting issues with the code that would cause it not to run.
88+
89+
1. Devise an AI prompt that removes any dead code from your sample above. What gets removed?
90+
91+
1. Create a prompt that makes the code less repetitive, adhering to the DRY principle. What aspect of the code was repetitive?
92+
93+
1. Construct a prompt that makes the code more concise. What are some trade-offs that appear in this code between readability and brevity?
94+

0 commit comments

Comments
 (0)