Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I don't understand what i'm doing wrong here:

This is the code challenge:

"I'm going to create a variable named time. It'll be an integer for the current hour (well, what I want the current hour to be).
I need you to make an if condition that sets store_open to True if time is in store_hours. If time isn't in store_hours, set store_open to False. You'll probably have to use if, else, and in to solve this one."

this is what i have typed in:

Python
store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
if "time" in store_hours:
    store_open = True
else:
    store_open = False



But i keep getting an error message that says :
"Bummer! `store_open` is not True."

What I have tried:

Everything.

I tried retyping it all.
I went back and re -watched the lesson and learned nothing new.
Posted
Updated 11-Oct-16 23:37pm
v2
Comments
Richard MacCutchan 12-Oct-16 4:22am    
You are looking for the string "time" in the array of integers, so that will never work. You need to create a variable named time that will be allocated some integer value indicating what the hour is.
CPallini 12-Oct-16 5:38am    
My virtual 5.
Richard MacCutchan 12-Oct-16 6:02am    
My virtual :thanks:

Following Richard's suggestion:
Quote:
You are looking for the string "time" in the array of integers, so that will never work. You need to create a variable named time that will be allocated some integer value indicating what the hour is.

try
Python
store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
time = 13
if time in store_hours:
    store_open = True
else:
    store_open = False

print store_open
 
Share this answer
 
Try:
Python
store_open = None
store_open = False
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
if "time" in store_hours:
    store_open = True
else:
    store_open = False


Advice:
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Debugging in Python | Python Conquers The Universe[^]
Debugging Python Like a Boss - The Zapier Engineering Blog - Zapier[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.

[Update]
Quote:
That doesn't work.
The change I gave you is about the error message you claim "Bummer! `store_open` is not True.".
I never said I did not suspect the if statement to be wrong.
And you need to learn the debugger soon.

By the way, giving error position also help us to see what is wrong.
I don't see any reason to get your error message in the code you provided, even the error message itself is weird.
 
Share this answer
 
v5
Comments
Daniel Choban 11-Oct-16 22:20pm    
That doesn't work.
Dave Kreskowiak 11-Oct-16 22:51pm    
Yeah, this is your homework. What he gave you is not real code that will copy'n'paste and run. You have to write the proper code yourself and you're not going to get anyone to do that for you.
Richard MacCutchan 12-Oct-16 5:16am    
It's not an error message, it's the message his code prints elsewhere when checking the value of store_open. See my comment above.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900