问题描述
我不明白我在这里做错了什么:
这是代码挑战:
我要创建一个名为time的变量。它将是当前小时的整数(好吧,我想要的是当前小时)。
我需要你创建一个if条件,如果时间在store_hours中,则将store_open设置为True。如果时间不在store_hours中,则将store_open设置为False。你可能必须使用if,else和in解决这个问题。
这就是我输入的内容:
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
但我不断收到一条错误消息:
坏消息! `store_open`不是真的。
我尝试过:
一切。
我尝试重新输入所有内容。
我回去重新学习课程并且没有学到任何新东西。
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.
推荐答案
你正在寻找整数数组中的字符串time,这样就永远不会有效了。你需要创建一个名为time的变量,它将被分配一些整数值来表示小时是什么。
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
store_open = False
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
if "time" in store_hours:
store_open = True
建议:
你应该学会尽快使用调试器可能。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。
调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。
[]
[]
[]
[ ]
调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。
[更新]
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]
这不起作用。
钍我给你的改变是关于你声称的错误信息糟糕! `store_open`不是真的。。
我从来没有说过我没有怀疑 if
语句是错误的。
你需要尽快学习调试器。
顺便提一下,给出错误位置也有助于我们看出错误。
我没有看到任何理由在您提供的代码中收到错误消息,即使错误消息本身也很奇怪。
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.
这篇关于我究竟做错了什么? (基础Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!