-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignments-05.qmd
96 lines (69 loc) · 3.33 KB
/
assignments-05.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
---
title: "Module 5 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 04
**Due date: `r assignments %>% filter(assessment == "Short Programming Project 4") %>% 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 9
**Due date: `r assignments %>% filter(assessment == "Module 5 Programming Problems") %>% pull(formatted_date)` at 9pm**
Write a Python function that does the following:
1. Its name is `count_vowels`
2. It takes one string as argument
3. It counts how many vowels there are in the string using a `while` loop
4. It returns an integer representing the number of vowels (`a`, `e` `i`, `o`, `u` -- both lowercase and uppercase) found in the argument
5. You can (and should) use the operator `in`
6. You are not allowed to use built-in count methods or functions
Name the program `vowels.py`. Make sure that gradescope gives you the points for passing the test cases.
Test cases for development:
```{python}
#| eval: false
#| echo: true
def main():
print( count_vowels("") ) # 0
print( count_vowels("aaa") ) # 3
print( count_vowels("AEIOU") ) # 5
print( count_vowels("cysts") ) # 0
main()
```
## Programming Problem 10
**Due date: `r assignments %>% filter(assessment == "Module 5 Programming Problems") %>% pull(formatted_date)` at 9pm**
Write a Python function that does the following:
1. Its name is `reverse_string`
2. It takes one string as argument
3. Using a `while` loop, it builds a new string that is the reverse of the original string
4. It returns the reversed string
Write a Python function that does the following:
1. Its name is `remove_spaces`
2. It takes one string as argument
3. Using a `while` loop to create a string with no spaces
4. Return the news string with no spaces
Write a Python function that does the following:
1. Its name is `is_palindrome`
2. It takes one string as argument
3. It checks whether the string is a palindrome. A Palindrome reads the same backward and forward. For example: madam, and nurses run
4. It returns `True` if the string is a palindrome, and `False` otherwise
5. Use your `remove_spaces` function to remove spaces from the argument before you check if the string is a palindrome
6. Use your `reverse_string` function to reverse the string and then compare the result to the original string
Name the program `palindrome.py`. Make sure that gradescope gives you the points for passing the test cases.
```{python}
#| eval: false
#| echo: true
def main():
print( reverse_string("aeiou") ) # uoiea
print( remove_spaces("ae io ua") ) # aeioua
print( is_palindrome("noon") ) # True
print( is_palindrome("deified") ) # True
print( is_palindrome("go deliver a dare vile dog") ) # True
main()
```