Outdated -Problem Set 3 (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 3, Outdated.

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.

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

this was really simple and yet very understandable. no fancy stuff. just sticking to the basics. Your channel deserve more subscribers brother. Thank you so much

tharindunawoda
Автор

This problem was the hardest up to this point for me.
I saw the "Dors Coding School" solution to this, and she made some nested try inside an except and it really confused me.
I'm glad to see it wasn't really needed.
I liked how you get to an input as soon as possible even if basic. And then start building from there adding more features and fixing the errors.
I don't like it when they code top to bottom as if they already know the program from memory, is not useful. this is!
Thanks!

HellmiauPlays
Автор

ı thought completely different but after this video ı changed my mind and use try except as you did

aliyilbasi
Автор

good job! I struggled with the ", " part but finally come up with pretty weird way (in short i checked if first character in outdated is alphabetic and if outdated[-6] equal, lol. I knew its not optimal way of solving this so I wanted to look for simpler ways. Nice video

infisspablo
Автор

thank you so much for taking the time to make this video. your videos have been so helpful!

deek
Автор

Very nice. Because I was splitting at the point of input I was struggling with the, bit.

TheStevenWhiting
Автор

Thank you Omar for your videos, I see the channel been inactive for 2 years but I really dig your way of explaining and I wonder how can I reach you?
Thank you

MoeAly
Автор

Great explanation, keep up the good work!

aigerimabseit
Автор

@Coding Pleasure Bro I'm struggling with this last one
: ( input of " 9/8/1636 " outputs 1636-09-08
Did not find "1636-09-08" in "Date: "
Please Please can you help me

mastergreen
Автор

love ur vids man, my solution was like 3x bigger than yours😅, but at least i did it by my own
my solution:
while True:
try:
data = input('data: ').title().strip()
except ValueError:
pass
if '/' in data:
x, y, z = data.split('/')
if x.isalpha() or y.isalpha() or z.isalpha():
pass
elif int(x) <= 12 and int(y) <= 31:

break
if ', ' in data:
data = data.replace(", ", "")
x, y, z = data.split(" ")
if x in meses and int(y) <= 31:
print(f'{z}-{meses.index(x) + 1:02}-{int(y):02}')
break

all :) in check50

cauecarvalho
Автор

I had some problems with the October/9/1701 and September 8 1636, I had to add else: continue but one of the two error kept staying depending if I was putting it after the Elif statement block or if statement block before the try:. I understood that I have to put both of them one under the other but with the correct indentation for the correct “equation”. Hard to explain but this is the code


list = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]

while True:

date = input("Date: " ).title()
if "/" in date:
m, d, y = date.split("/")

elif ", " in date:
date = date.replace(", ", "")
m, d, y = date.split(" ")

if m in list:
m = list.index(m) + 1
else:
continue
else:
continue

try:
if int(m) > 12 or int(d) > 31:
continue
else:
break
except (ValueError, EOFError):
continue


jimmypaquette
Автор

Didn't work for me. I ended up with this solution:

months = [ etc etc ]

while True:
date = input("Date: ")
if ", " in date:
month, day, year = date.replace(", ", " ").split()
try:
day = int(day)
year = int(year)
except ValueError:
continue
if day > 31 or month not in months:
continue
else:
month = months.index(month) + 1
break
elif "/" in date:
month, day, year = date.replace("/", " ").split()
try:
month = int(month)
day = int(day)
year = int(year)
except ValueError:
continue
if day > 31 or month > 12:
continue
break
else:
continue


lefordiando
Автор

Hi sir, I do not understand the logic behind months.index(month)+1 i did was to turn the month into a dict ==> month = {"January":1 , "February": 2 etc etc}

so here is my code (part of it)

if d > 31 or m not in month:
continue

else:
n = month[m]
print(f"{y}-{n:02}-{d:02}")


it d be nice if you could explain what months.index(month)+1 is or where can i look up what it is

brucebergkamp
Автор

i have an error of
input of 10/9/1710 outputs 1710-10-09
did not find "1710-10-09" in"date:"
how to correct this

divyalakshmi
Автор

hey bro .. i wrota a program with tkinter for final project.. but i cant run that on code space ..

error :

root=Tk() File "/usr/local/lib/python3.10/tkinter/__init__.py", line 2299, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: couldn't connect to display ":0"

its work on vscode but not working on code space

northernviber
Автор

i think you have finished CS50P, what you are currently doing ? you are amazing 😊😊

janajit
Автор

Hi help me, input of October/9/1701 result in reprobate expected program to reject input, but it did not, I don't know what I did mistake.

saimurugeshwari
Автор

is there anyway i can contact you ? i'm looking for a mentor if you do provide the service

JimProductions
Автор

Sharing the code I made because it took me hours to make all the checking prompts green T_T:

def main():

months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]


while True:
dates = input("Date: ")
if "/" in dates:
dates = dates.strip()
month, day, year = dates.split("/")
elif ", " in dates:
dates = dates.replace(", ", "")
parts = dates.split(" ")
month = parts[0]
day = parts[1]
year = parts[2]

if month in months:
month = months.index(month) + 1
else:
continue
else:
continue
try:
if int(month) > 12 or int(day) > 31:
continue
else:
break
except ValueError:
continue



if __name__ == "__main__":
main()

angelcoolkid
Автор

Try This


months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
def main():
while True:
date = input('Date: ')
try:
mnth, day, year = date.split('/')
mnth = int(mnth)
day = int(day)
year = int(year)
if (int (mnth) > 0 and int(mnth) < 13) and (int(day) > 0 and int(day) < 32):
if year >= 1000 and year <= 9999:
print (year, f'{mnth:02}', f'{day:02}', sep='-')
break
except:
try:
if ", " in date:
mnth, day, year = date.split(' ')
day = day.replace(', ', '')
day = int(day)
year = int(year)
if mnth in months and (int(day) > 0 and int(day) < 32):
if year >= 1000 and year <= 9999:
mnth= (months.index (mnth)+1)
print (year, f'{mnth:02}', f'{day:02}', sep = '-')
break
except:
pass

main()

thetechmask
join shbcf.ru