-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignments-06.qmd
97 lines (66 loc) · 3.16 KB
/
assignments-06.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
title: "Module 6 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 05
**Due date: `r assignments %>% filter(assessment == "Short Programming Project 5") %>% 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 11
**Due date: `r assignments %>% filter(assessment == "Module 6 Programming Problems") %>% pull(formatted_date)` at 9pm**
Write a Python function that does the following:
1. Its name is `sum_all`
2. It takes a list of numeric values as argument: `numbers`
3. It returns the sum of all elements in `numbers`
4. Use a `while` loop (define an index before the loop, use index in the `while` condition, change the index inside the loop)
Name the program `sum.py`. Make sure that gradescope gives you the points for passing the test cases.
Test cases:
```{python}
#| eval: false
#| echo: true
def main():
value = sum_all([])
assert value == 0, f"expected return value was 0, but function returned {value}"
value = sum_all([0, 0, 0, 0, 0])
assert value == 0, f"expected return value was 0, but function returned {value}"
value = sum_all([1, -1, 2, -2, 3, -3])
assert value == 0, f"expected return value was 0, but function returned {value}"
value = sum_all([1, 2, 3, 4, 5])
assert value == 15, f"expected return value was 15, but function returned {value}"
print("All tests passed.")
main()
```
## Programming Problem 12
**Due date: `r assignments %>% filter(assessment == "Module 6 Programming Problems") %>% pull(formatted_date)` at 9pm**
Write a Python function that does the following:
1. Its name is `concatenate`
2. It takes a list of strings as argument: `words`
3. It returns a string with all items in `words` concatenated and separated by spaces
4. Use a `while` loop (define an index before the loop, use index in the `while` condition, change the index inside the loop) -- the last word in the resulting string is not followed by space
Name the program `concatenate.py`. Make sure that gradescope gives you the points for passing the test cases.
Test cases:
```{python}
#| eval: false
#| echo: true
def main():
value = concatenate([])
assert value == "", \
f"expected return value was an empty string, but function returned {value}"
value = concatenate(["", "", ""])
assert value == " ", \
f"expected return value was an \" \", but function returned {value}"
value = concatenate(["Hi", "there"])
assert value == "Hi there", \
f"expected return value was an \"Hi There\", but function returned {value}"
print("All tests passed.")
main()
```