Variable referenced before assignment

Tell us what’s happening:
I have a very rough code for the program but I’m getting an error that variable s is referenced before assignment. If anyone could help me regarding what I may be doing wrong or point me to what the problem may be. It is a very rough code and I do plan on refining it…

Your code so far

Your browser information:

User Agent is: Chrome/93.0.4577.82

Challenge: Time Calculator

Link to the challenge:

I’m not a python guy, but…

  if day== None:
    if l==0:
      s=time+" "+str(ap)
    elif l>0:
      s=time+" "+str(ap)+str(days)
  else:
    if l==0:
      s=time+" "+str(ap)+day
    elif l==1:
      s=time+" "+str(ap)+day+str(days)
  return s

What if day is not equal to None and l is 2? I think s never gets assigned.

1 Like

thats it! thanks!
thats solved but theres another issue now… the days are showing up as

<built-in method capitalize of str object at 0x7f54ddabf270>

so the answer when it needs to be 5:24 AM, Monday is:

5:24 AM<built-in method capitalize of str object at 0x7f54ddabf270>

that seems to be as if you have concatenated a method to a string, when you wanted the output of the method

1 Like

so if I do the folowing, it wont work?

s=string.capitalize()
t="trial"+s

you can add print(t) to check the value

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.