FAQ: Control Flow - Review

@data4697612999 @gr3y_ht Seems like you guys have similar issues. You can use a second if / else statement block before printing. Not the most elegant solution but within what’s being taught in the course at this point. Defining a function and have a if statement at the function call may also help.

Here’s my solution:

print("I have information for the following planets:\n") print(" 1. Venus 2. Mars 3. Jupiter") print(" 4. Saturn 5. Uranus 6. Neptune\n") weight = 185 planet = 3 # Write an if statement below: if planet == 1: planet_name = "Venus" destination_weight = weight * 0.91 elif planet == 2: planet_name = "Mars" destination_weight = weight * 0.38 elif planet == 3: planet_name = "Jupiter" destination_weight = weight * 2.34 elif planet == 4: planet_name = "Saturn" destination_weight = weight * 1.06 elif planet == 5: planet_name = "Uranus" destination_weight = weight * 0.92 elif planet == 6: planet_name = "Neptune" destination_weight = weight * 1.19 else: print('That is not a valid planet on the list!') if planet in (1,2,3,4,5,6): print("You are going to " + planet_name + "! Your weight at the destination planet will be " + str(round(destination_weight, 1)) + " lbs.")

Hi all, in the final exercise there is a /n in the first 2 prints that do not show in the console when run. Can anyone explain to me what they are e.g.:

print(“I have information for the following planets:\n”)

print(" 1. Venus 2. Mars 3. Jupiter")
print(" 4. Saturn 5. Uranus 6. Neptune\n")

Nvm, think I found the answer
" In Python, \n is a type of escape character that will create a new line when used . There are a few other escape sequences, which are simple ways to change how certain characters work in print statements or strings."

1 Like