Code Review Reuqest The Big IF


#1

Make sure that the_flying_circus() returns True

Disregard this was not meeting the main objective of the assignment. Please inform why conditions after dagger cannot be formatted. Such as 'bow' selection, will still print print ("Excellent selection %s, %s shall bode you well") % (user_name, user_weapon) rather than print ("Excellent selection %s, a %s shall bode you well") % (user_name, user_weapon). Please advise I cannot find any restrictions on elif's. Thanks!

user_name = raw_input ("What is your name?")

def the_flying_circus():
return True
print "You have entered a dungeon"
print "There are several weapons to choose from"
user_weapon = raw_input ("Please select from the cavalier: Sword, Daggers, Bow & Quiver, Rifle").lower()

if user_weapon == "sword":
print ("Excellent selection %s, a %s shall bode you well") % (user_name, user_weapon)

elif user_weapon == "daggers" or "dagger":
print ("Excellent selection %s, %s shall bode you well") % (user_name, user_weapon)

elif user_weapon == "bow & quiver" or "bow" or "bow and quiver":
print ("Excellent selection %s, a %s shall bode you well") % (user_name, user_weapon)

elif user_weapon == "rifle" or "gun":
print ("Shit just got real %s, a %s shall bode you well") % (user_name, user_weapon)

else:
print ("Please select from the valid options: Sword, Daggers, Bow & Quiver, M16")


#2

Hi @pattjaso ,

Because your code is not formatted, it is difficult for other users to read and debug it. After code is been pasted into the editing window for posting, you can format it by selecting it, and then by clicking the </> button above the editing area. This will enable us to see important details, such as the indentation and underscores.

There are multiple issues that need to be addressed in order for your code to work as intended.

The first statement inside the the_flying_circus function is ...

return True

This will cause it to return immediately, and no additional statements inside the function will be executed.

You have a raw_input statement inside your the_flying_circus function. While such statements are allowed inside functions, there will be no user interaction when Codecademy calls the function to test it, so execution would get stuck, if it ever did reach that point.

This expression ...

"bow & quiver" or "bow" or "bow and quiver"

... always evaluates to "bow and quiver".


#3

Ah that all makes perfect sense; please know I had not learned functions yet before having this thrown at me in a lesson. However, I did continue to play with this Code outside of Code Academy. Good to know about raw_input/input limitations within a function as well. Why is it that the expression:

"bow & quiver" or "bow" or "bow and quiver"

always evaluates to "bow and quiver"?

Are we limited to only two parameters for 'or'.

Thanks for your help - I am still confused on why the options do not permit past the dagger submissions. It seems even if a user was to submit "bow and quiver", it still prints the statement for dagger selections. Could you elaborate on why?

Possibly you could give insight on the below:

user_name = raw_input ("What is your name?")

print "You have entered a dungeon"
print "There are several weapons to choose from"
user_weapon = raw_input ("Please select from the cavalier: Sword, Daggers, Bow & Quiver, Rifle").lower()

if user_weapon == "sword":
    print ("Excellent selection %s, a %s shall bode you well") % (user_name, user_weapon)

elif user_weapon == "daggers" or "dagger":
    print ("Excellent selection %s, %s shall bode you well") % (user_name, user_weapon)

elif user_weapon == "bow & quiver" or "bow" or "bow and quiver":
    print ("Excellent selection %s, a %s shall bode you well") % (user_name, user_weapon)

elif user_weapon == "rifle" or "gun":
    print ("Shit just got real %s, a %s shall bode you well") % (user_name, user_weapon)

else:
    print ("Please select from the valid options: Sword, Daggers, Bow & Quiver, M16")