There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
It looks to be working in the exercise environment. Perhaps it is not being accepted by the lesson checker? If not, then remove the print statements and only print the return value at the caller.
I seem to be misunderstanding boolean operators. I’ve made an attempt at adding a little extra to exercise 17/19, but have run into a problem.
userInput = raw_input("Shutdown?(yes/no):")
def shut_down(s):
#shutdown approved if user enters "yes" or "y"
if s.lower() == ("yes" or "y"):
return "Shutting down"
#shutdown prevented if user enters "yes" or "y"
elif s.lower() == ("no" or "n"):
return "Shutdown aborted"
else:
return "Inappropriate Input"
print shut_down(userInput)
When I try to use “y” or “n” as an input the program runs the else condition. Am I misusing the or operator? Is it a syntax error?
It will work if I use the or operator for 2 expressions instead of 2 arguments:
userInput = raw_input("Shutdown?(yes/no):")
def shut_down(s):
#lowercase return of userInput
x = s.lower()
#shutdown approved if user enters "yes" or "y"
if x == "yes" or x == "y":
return "Shutting down"
#shutdown prevented if user enters "yes" or "y"
elif x == "no" or x == "n":
return "Shutdown aborted"
else:
return "Inappropriate Input"
print shut_down(userInput)
I think it’s because after return you are calling for the function shut_down instead of returning the string “Shutting down”. This will cause an infinite loop.
I am stuck on this one too. Here is the code that I am trying to use:
def shut_down(s):
if shut_down(s) == "yes":
return "Shutting down"
elif s == "no":
return "Shutdown aborted"
else:
return "Sorry"
Based on the instructions, as far as I can tell, this is all that I need to do, however I keep throwing errors. As I currently have it setup above, I get this error: “Your shut_down function threw the following error: maximum recursion depth exceeded”. Without the extra indentation, and formatting my code to look like the example, I get this error: “Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Your code threw the following error: expected an indented block…”.
the terminal tells you where there is a syntax error. return keyword can only be used within a function. Which you don’t do
the bigger problem is the program you are asked to make follows a very different design then the example provided in the lesson. You can’t just go about copying code and changing a few things hoping it works