Click here to Skip to main content
13,629,232 members
Rate this:
 
Please Sign up or sign in to 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:

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 11-Oct-16 14:30pm
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:
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try:
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.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.180712.1 | Last Updated 12 Oct 2016
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100