PROBLEM SET 5: TESTING MY TWTTR | SOLUTION (CS50 PYTHON)

preview_player
Показать описание


––– DISCLAIMER –––
The following videos are for educational purposes only. Cheating or any other activities are highly discouraged!! Using another person’s code breaks the academic honesty guidelines. This solution is for those who have finished the problem sets and want to watch for educational purposes, learning experience, and exploring alternative ways to approach problems and is NOT meant for those actively doing the problem sets. All problem sets presented in this video are owned by Harvard University.
–––
Рекомендации по теме
Комментарии
Автор

Thank you! I had no idea CS50 Python did not consider a quote and a question mark as punctuation marks. I wish I had seen your video BEFORE wasting so much time going nowhere; the problem sets are not accurately worded. Very glad to donate, plus I have subscribed.

rongarza
Автор

Thank you, that was very helpful in removing the frustration I was feeling not being able to resolve the numbers and punctuation errors.

voicevoicelessKrzysiek
Автор

The problem description should state that CHECK50 doesn't consider a question mark and single and double quotes as punctuation marks. Your video saved me a lot of time and frustration. I have subscribed and donated using the Heart $ Thanks button above.

rongarza
Автор

Thanks, after watching your video I realized that all I needed was
implementing a "test_number" function as well!

David-eblh
Автор

I really appreciate the clear explanation in your video. It helped a lot.

orkhanmammadov
Автор

After many hours. Here is my solution for people stuck. I do recommend trying to figure it out on your own...

def main():
message = input("Input: ")
msg_wo_vowels = shorten(message)
print("Output: " + msg_wo_vowels)


def shorten(word):
wo_vowels = ""
for letter in word:
if not letter.lower() in ["a", "e", "i", "o", "u"]:

wo_vowels += letter
return wo_vowels


if __name__ == "__main__":
main()

Landry_Houston
Автор

We actually don't need to have a main() in the test_file, in the class they explain that when using pytest we just need to create the test_functions and assertions :)

angelicandoo
Автор

I was trying to use return inside the if condition inside the for loop, so it was just returning the first letter and breaking out of the loop.
To fix that, I used .replace inside def shorten(word) to replace every single vowel, although it worked, it looked a little bit ugly and repetitive.
Thanks for enlightening me.

luanpires
Автор

def main():
user_input = input("Enter a text: ")
result = shorten(user_input)
print("Text without vowels:", result)



def shorten(text):
vowels = "aeiouAEIOU"
result = ''.join(char for char in text if char not in vowels)
return result



if __name__ == "__main__":
main()

IgorVetkin-db
Автор

Personally don't think there's a need to create an empty variable and then add letters to it. You can simply use the replace() function to remove the vowels as I've shown below:

def main():
prompt = input('Input: ')
print(shorten(prompt))

def shorten(word):
for vowel in ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']:
word = word.replace(vowel, '')
return word

if __name__ == '__main__':
main()

NomadLovesUs
Автор

thank you so much, explained the concept very well

aa-mykl
Автор

weird question but how many files are supposed to be in submit50? 2? It says my /twttr.py will not be included? DO I need the for full credit?

World_Tech_and_Cybersecurity
Автор

Thank you so much for the video, i just didn't understand why are we calling the test function in the test_twttr.py file . i mean there is no reason to call them since the pytest function could work without doing that with no issues.

b.her_
Автор

icant import the shorten function its tells me ImportError

wing
Автор

My code:

tweet = input("Input: ")
print("Output: ", end="")
for letter in tweet:
if letter in ["A", "E", "I", "O", "U", "a", "e", "i", "o", "u"]:
continue
else:
print(letter, end="")
print()

Georgetvl
Автор

it says no tests ran oin 0.00 secs how do i fix it?

Upanya-Ch
Автор

Hi Giovanna, I am getting an "Invalid slug" error during my check50. Any idea how to fix this? Thanks in advance

federicoelevazo
Автор

Can you help? I keep getting this: :( correct twttr.py passes all test_twttr checks
expected exit code 0, not 1

roystn
Автор

she keeps saying it every time in the intro, yet a lot of people just come here to copy

mikebrignol
Автор

my pytest was passing all the tests except the check50 one it kept saying that it expects exit code 0 not 1

AK.
welcome to shbcf.ru