-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignments-08.qmd
77 lines (53 loc) · 2.92 KB
/
assignments-08.qmd
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
title: "Module 8 Assignments"
---
```{r}
#| echo: false
#| message: false
#| warning: false
library(tidyverse)
library(readxl)
assignments <- read_excel("assessment_schedule.xlsx") %>%
mutate(formatted_date = format(due_date, "%A, %B %d, %Y"))
```
# Short Project 07
**Due date: `r assignments %>% filter(assessment == "Module 8 Programming Problems") %>% pull(formatted_date)` at 9pm**
Short Programming projects are submitted during our weekly 45-minute in-person lab sessions. Each lab sessions is guided by two TAs. The instructions for the short project will be available only during the lab sessions. To schedule your lab session go to the weekly lab session spreadsheet in [Short Project Dates and Instructions](short-projects.html).
# Programming Problems
Programming Problems should be submitted to [gradescope](https://www.gradescope.com/courses/934148).
## Programming Problem 15
**Due date: `r assignments %>% filter(assessment == "Module 8 Programming Problems") %>% pull(formatted_date)` at 9pm**
Write a Python function that does the following:
1. Its name is `count_vowels`
2. It takes as argument a `string`
3. It iterates over the `string` (either with a `while` or `for` loop) counting how many lowercase and uppercase vowels the `string` has
4. It returns a **dictionary** with vowels are the keys, and integer counts as the values
Test cases:
```{python}
#| echo: true
#| eval: false
print( count_vowels("") ) # {"a": 0, "e": 0, "i": 0, "o": 0, "u": 0,
# "A": 0, "E": 0, "I": 0, "O": 0, "U": 0}
print( count_vowels("banana") ) # {"a": 3, "e": 0, "i": 0, "o": 0, "u": 0,
# "A": 0, "E": 0, "I": 0, "O": 0, "U": 0}
print( count_vowels("Adriana") ) # {"a": 2, "e": 0, "i": 1, "o": 0, "u": 0,
# "A": 1, "E": 0, "I": 0, "O": 0, "U": 0}
print( count_vowels("Hello World!") ) # {"a": 0, "e": 1, "i": 0, "o": 2, "u": 0,
# "A": 0, "E": 0, "I": 0, "O": 0, "U": 0}
```
Name the program `vowel_counting.py`. Make sure that gradescope gives you the points for passing the test case.
## Programming Problem 16
**Due date: `r assignments %>% filter(assessment == "Module 8 Programming Problems") %>% pull(formatted_date)` at 9pm**
Write a Python function that does the following:
1. Its name is `invert_dictionary`
2. It takes a single `dictionary` as a parameter
3. It returns a new dictionary with the original `dictionary` values mapped as keys, and its original keys mapped as lists of values
Test cases:
```{python}
#| echo: true
#| eval: false
print( invert_dictionary({"a": 7, "b": 8}) ) # { 7: ["a"], 8: ["b"] }
print( invert_dictionary({"a": 2, "b": 2}) ) # { 2: ["a", "b"] }
print( invert_dictionary({}) ) # {}
```
Name the program `inversion.py`. Make sure that gradescope gives you the points for passing the test case.