Deep Thought -Problem Set 1 (CS50's Introduction to Programming with Python)

preview_player
Показать описание
Hello, everyone and welcome to another video, in this video, I will explain and solve problem set 1, Deep Thought.

if you haven't already submitted this problem, You have to try this on your own.
This video is to just give you a way to solve this problem , try solving it using a different approach, to get the most benefits out of this experience.

Don't forget to hit the like button and subscribe to the channel, and if you have any questions or want an explanation for a specific problem leave a comment down below.

Рекомендации по теме
Комментарии
Автор

I did it like this:

answer = input(" What is the Answer to the Great Question of Life, the Universe, and Everything? ").lower().strip()

match answer:
case "42" | "forty two" | "forty-two":
print("Yes")
case _:
print("No")

iliutacristian
Автор

I used replace() to get rid of hyphens if the user writes them

right1 = "42"
right2 = "forty two"
answer = input("What's the meaning of life?: ").replace("-", " ").lower().strip()
if answer == right2 or answer == right2
print("Correct")

Sbkoihvff
Автор

Here i am on first assignment, cheating already xD

Coltwhyte
Автор

1 answer = input ("What's the answer?") .strip()
2
3 if answer . lower() in ["42", "forty two", "forty-two"]:
4 ....print("Yes")
5
6 else:
7 ....print ("No")

chooselife
Автор

i just added another replace("-", " ") to the chain, then "forty two" or "42" is enough.

rabenfedersonnenhut
Автор

str_input = input('What is the Answer to the Great Question of Life, the Universe, and Everything?')

formated_str = str_input.lower().strip().replace('-', ' ')
valid_words = ['forty', 'two']

valid_number_answer = formated_str.isnumeric() and float(formated_str) == 42
valid_str_answer = any(word in formated_str for word in valid_words)

print('Yes') if valid_number_answer or valid_str_answer else print('No')

leakim
Автор

answer = input("What is the Answer to the Great Question of Life, the Universe, and Everything? ").casefold().strip()

match answer:
case "42" | "forty two" | "forty-two":
print("Yes")
case _:
print("No")

Mxrxus_
Автор

# forty-two forty two FORTY TWO
answer =input('What is the answer for the great Question of Life, the Universe and
if answer == '42' or answer == 'forty-two' or answer == 'forty two':
print('Yes')
else:
print('No')

heitorleal