|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +# Writing Code: Hands-On Exercise |
| 6 | + |
| 7 | +Now it’s your turn to try! |
| 8 | + |
| 9 | +## Code |
| 10 | + |
| 11 | +Here's the code you need for question #2. |
| 12 | + |
| 13 | +``` |
| 14 | +def calculate_average(numbers): |
| 15 | + total = 0 |
| 16 | + for number in numbers: |
| 17 | + total += number |
| 18 | + average = total / len(numbers) |
| 19 | + return average |
| 20 | +
|
| 21 | +numbers = [1, 2, 3, 4, "5"] |
| 22 | +average = calculate_average(numbers) |
| 23 | +print("The average of the numbers is:", average) |
| 24 | +``` |
| 25 | + |
| 26 | +## Questions |
| 27 | + |
| 28 | +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. |
| 29 | + |
| 30 | +1. Write a query that helps you debug the code snippet from above. |
| 31 | + |
| 32 | +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. |
| 33 | + |
| 34 | +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. |
| 35 | + |
| 36 | +1. Create a prompt that identifies the best coding language for the above game. |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +```r |
| 42 | +devtools::session_info() |
| 43 | +``` |
| 44 | + |
| 45 | +``` |
| 46 | +## ─ Session info ─────────────────────────────────────────────────────────────── |
| 47 | +## setting value |
| 48 | +## version R version 4.0.2 (2020-06-22) |
| 49 | +## os Ubuntu 20.04.5 LTS |
| 50 | +## system x86_64, linux-gnu |
| 51 | +## ui X11 |
| 52 | +## language (EN) |
| 53 | +## collate en_US.UTF-8 |
| 54 | +## ctype en_US.UTF-8 |
| 55 | +## tz Etc/UTC |
| 56 | +## date 2023-11-01 |
| 57 | +## |
| 58 | +## ─ Packages ─────────────────────────────────────────────────────────────────── |
| 59 | +## package * version date lib source |
| 60 | +## assertthat 0.2.1 2019-03-21 [1] RSPM (R 4.0.5) |
| 61 | +## bookdown 0.24 2023-03-28 [1] Github (rstudio/bookdown@88bc4ea) |
| 62 | +## bslib 0.4.2 2022-12-16 [1] CRAN (R 4.0.2) |
| 63 | +## cachem 1.0.7 2023-02-24 [1] CRAN (R 4.0.2) |
| 64 | +## callr 3.5.0 2020-10-08 [1] RSPM (R 4.0.2) |
| 65 | +## cli 3.6.1 2023-03-23 [1] CRAN (R 4.0.2) |
| 66 | +## crayon 1.3.4 2017-09-16 [1] RSPM (R 4.0.0) |
| 67 | +## desc 1.2.0 2018-05-01 [1] RSPM (R 4.0.3) |
| 68 | +## devtools 2.3.2 2020-09-18 [1] RSPM (R 4.0.3) |
| 69 | +## digest 0.6.25 2020-02-23 [1] RSPM (R 4.0.0) |
| 70 | +## ellipsis 0.3.1 2020-05-15 [1] RSPM (R 4.0.3) |
| 71 | +## evaluate 0.20 2023-01-17 [1] CRAN (R 4.0.2) |
| 72 | +## fansi 0.4.1 2020-01-08 [1] RSPM (R 4.0.0) |
| 73 | +## fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.0.2) |
| 74 | +## fs 1.5.0 2020-07-31 [1] RSPM (R 4.0.3) |
| 75 | +## glue 1.4.2 2020-08-27 [1] RSPM (R 4.0.5) |
| 76 | +## hms 0.5.3 2020-01-08 [1] RSPM (R 4.0.0) |
| 77 | +## htmltools 0.5.5 2023-03-23 [1] CRAN (R 4.0.2) |
| 78 | +## jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.0.2) |
| 79 | +## jsonlite 1.7.1 2020-09-07 [1] RSPM (R 4.0.2) |
| 80 | +## knitr 1.33 2023-03-28 [1] Github (yihui/knitr@a1052d1) |
| 81 | +## lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.0.2) |
| 82 | +## magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.0.2) |
| 83 | +## memoise 2.0.1 2021-11-26 [1] CRAN (R 4.0.2) |
| 84 | +## ottrpal 1.0.1 2023-03-28 [1] Github (jhudsl/ottrpal@151e412) |
| 85 | +## pillar 1.9.0 2023-03-22 [1] CRAN (R 4.0.2) |
| 86 | +## pkgbuild 1.1.0 2020-07-13 [1] RSPM (R 4.0.2) |
| 87 | +## pkgconfig 2.0.3 2019-09-22 [1] RSPM (R 4.0.3) |
| 88 | +## pkgload 1.1.0 2020-05-29 [1] RSPM (R 4.0.3) |
| 89 | +## prettyunits 1.1.1 2020-01-24 [1] RSPM (R 4.0.3) |
| 90 | +## processx 3.4.4 2020-09-03 [1] RSPM (R 4.0.2) |
| 91 | +## ps 1.4.0 2020-10-07 [1] RSPM (R 4.0.2) |
| 92 | +## R6 2.4.1 2019-11-12 [1] RSPM (R 4.0.0) |
| 93 | +## readr 1.4.0 2020-10-05 [1] RSPM (R 4.0.2) |
| 94 | +## remotes 2.2.0 2020-07-21 [1] RSPM (R 4.0.3) |
| 95 | +## rlang 1.1.0 2023-03-14 [1] CRAN (R 4.0.2) |
| 96 | +## rmarkdown 2.10 2023-03-28 [1] Github (rstudio/rmarkdown@02d3c25) |
| 97 | +## rprojroot 2.0.3 2022-04-02 [1] CRAN (R 4.0.2) |
| 98 | +## sass 0.4.5 2023-01-24 [1] CRAN (R 4.0.2) |
| 99 | +## sessioninfo 1.1.1 2018-11-05 [1] RSPM (R 4.0.3) |
| 100 | +## stringi 1.5.3 2020-09-09 [1] RSPM (R 4.0.3) |
| 101 | +## stringr 1.4.0 2019-02-10 [1] RSPM (R 4.0.3) |
| 102 | +## testthat 3.0.1 2023-03-28 [1] Github (R-lib/testthat@e99155a) |
| 103 | +## tibble 3.2.1 2023-03-20 [1] CRAN (R 4.0.2) |
| 104 | +## usethis 1.6.3 2020-09-17 [1] RSPM (R 4.0.2) |
| 105 | +## utf8 1.1.4 2018-05-24 [1] RSPM (R 4.0.3) |
| 106 | +## vctrs 0.6.1 2023-03-22 [1] CRAN (R 4.0.2) |
| 107 | +## withr 2.3.0 2020-09-22 [1] RSPM (R 4.0.2) |
| 108 | +## xfun 0.26 2023-03-28 [1] Github (yihui/xfun@74c2a66) |
| 109 | +## yaml 2.2.1 2020-02-01 [1] RSPM (R 4.0.3) |
| 110 | +## |
| 111 | +## [1] /usr/local/lib/R/site-library |
| 112 | +## [2] /usr/local/lib/R/library |
| 113 | +``` |
| 114 | + |
| 115 | + |
0 commit comments