CS50 Lesson 6

CS50
code
lesson
Author

Ryan curtis

Published

April 12, 2023

I thought it would be fun to track all of my progress learning python, even the VERY humble beginnings. Any of the posts with the CS50 tag are simply copy/pastes of my code from lessons, along with a copy/paste of what the assignment actually wanted me to do for context.

This was the final lesson I did for this course as from this point on, the lessons became moreso about development and software testing, things which fell outside of the scope of data visualization. I also felt that I had a faily solid grasp of the fundamentals of Python by this point, so I elected to begin pursuing my own projects and challenges.

Testing my twttr

In a file called twttr.py, reimplement Setting up my twttr from Problem Set 2, restructuring your code per the below, wherein shorten expects a str as input and returns that same str but with all vowels (A, E, I, O, and U) omitted, whether inputted in uppercase or lowercase.

def main():
  ...   

def shorten(word):     
  ...   
  
if __name__ == "__main__":     
  main()
  

##twttr.py##

```{{python}}
def main():
    user_input = input("Input: ").strip()
    twttr_sentence = shorten(user_input)
    print(twttr_sentence)
    

def shorten(word):
    twttr_sentence = []

    for letter in word:
        match letter.lower():
            case "a" | "e" | "i" | "o" | "u":
                pass
            case _:
                twttr_sentence.append(letter)

    #Join list to single string and return
    twttr_sentence = "".join(twttr_sentence)
    return(twttr_sentence)


if __name__ == "__main__":
    main()
```

##test_twttr.py##

```{python}
from twttr import shorten

def test_shorten_all_vowels():
    assert shorten("aeiou") == ""

def test_shorten_caps_check():
    assert shorten("RYAN") == "RYN"

def test_shorten_numbers():
    assert shorten("number21") == "nmbr21"

def test_shorten_punctuation():
    assert shorten("twitter.py") == "twttr.py"
```

Back to the Bank

In a file called bank.py, reimplement Home Federal Savings Bank from Problem Set 1, restructuring your code per the below, wherein value expects a str as input and returns 0 if that str starts with "hello", 20 if that str starts with an "h" (but not "hello"), or 100 otherwise, treating the str case-insensitively. You can assume that the string passed to the value function will not contain any leading spaces. Only main should call print.

def main():    
  ... 
  
def value(greeting):     
  ...   
  
if __name__ == "__main__":     
  main()

##bank.py##

```{{python}}
def main():
    #Get user input & strip & convert to lowercase
    user_input = input("How would you like to greet the patron? ").strip().lower()
    payout = value(user_input)
    print(payout)

def value(greeting):
#If they say hello, give $0
    if greeting == "hello":
        return("$0")

    #if string is not just "hello", split string up to isolate greeting word, then match each case to their respective payouts
    else:
        greet_word, dump1 = greeting.split(" ", 1)
        match greet_word:
            case "hello,":
                return("$0")
            case "hello":
                return("$0")
            case "how":
                return("$20")
            case _:
                return("$100")

if __name__ == "__main__":
    main()
```

##test_bank.py##

```{python}
from bank import value

def test_value_correct():
    assert value("Hello, Ryan") == "$0"
    assert value("How are you?") == "$20"
    assert value("What's up?") == "$100"
```

Just setting up my twttr

```{{python}}

```

Coke Machine

``` {{python}}

```

camelCase

```{{python}}

```