0

I'm doing the problem set 1 on CS50P course and on the "Meal Time" problem I can't get a check from check50.
The code runs fine if I test manually but check50 returns 'cant check until a frown turns upside down' on every test after the second one (which doesn't pass).
I made some mistake for sure but the code runs fine so there must be something I'm missing?

time = input("What time is it?: ")

def main(x):
    x = convert(x)
    if x >= 7 and x <= 8.00 :
        print("breakfast time")

    elif x >= 12 and x <= 13 :
        print("lunch time")

    elif x >= 18 and x <= 19 :
        print("dinner time")



def convert(x):
    if ":" in x :
        x = x.split(":")
        x = (int(x[1]) / 60) + int(x[0])
        return float(x)

main(time)


if __name__ == "__main__":
    main()
1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Commented Nov 7, 2023 at 20:52

1 Answer 1

1

Among other potential problems the main problem is that you are calling main without an argument when run on command line, and then calling main again in your code when executed.

I would strongly suggest that you put the line time = input("What time is it?: ") inside of main, and secondly delete the line of code that says main(time) it is unneeded and wrong.

other errors are fixed below too with comments

then change x = convert(x) to x = convert(time) so it looks like so:


def main():
    time = input("What time is it?: ")
    x = convert(time)

    if x >= 7.00 and x <= 8.00 : # note adjustment to 7 to be floats
        print("breakfast time")
    elif x >= 12.00 and x <= 13.00 : # adjustment to 12 and 13 to be floats
        print("lunch time")
    elif x >= 18.00 and x <= 19.00 : # adjustment to 18 and 19 to be floats
        print("dinner time")


def convert(x):
    if ":" in x :
        x = x.split(":")
        x = (float(x[1]) / 60.0) + float(x[0])  # note switch from int to float
        return float(x)

if __name__ == "__main__":
    main()

1
  • Thank you very much! Still a newbie here ahaha
    – FSZer0
    Commented Nov 8, 2023 at 2:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .