- 1

how to add given character, word or string to final line

this is my code I think code is good what I'm trying to accomplish is regardless of what kind of results "Moon" shows on end of line. I may have final result "super blue blood" or "super blue" it mast be displaing on single line and 'Moon' appearing on end of line just one time. Thank You moon_1="Super" moon_2="Blue" moon_3="Blood" #Add your code here! if phase=="Full": if distance<230000: print("Super",end=" ") if date==29 or date==30 or date==31: print("Blue",end=" ") if eclipse==1: print("Blood",end=" ") else: if date==29 or date==30 or date==31: print("Blue",end=" ") if eclipse==1: print("Blood") else: print("Moon")

18th Sep 2018, 4:47 AM
Ireneusz Rapa
Ireneusz Rapa - avatar
4 Answers
+ 1
Remove the else part off the "Phase" branch, and move the branches for "date" and "eclipse" outside the branch of "distance", they are the same anyways ... moon_1="Super" moon_2="Blue" moon_3="Blood" #Add your code here! phase = "Full" distance = 229999 date = 30 eclipse = 1 if phase == "Full": if distance < 230000: print(moon_1, end = " ") if date >= 29 and date <= 31: print(moon_2, end = " ") if eclipse == 1: print(moon_3, end = " ") print("Moon")
18th Sep 2018, 6:08 AM
Ipang
0
Remove the last else so it always prints moon moon_1="Super" moon_2="Blue" moon_3="Blood" #Add your code here! if phase=="Full": if distance<230000: print("Super",end=" ") if date==29 or date==30 or date==31: print("Blue",end=" ") if eclipse==1: print("Blood",end=" ") else: if date==29 or date==30 or date==31: print("Blue",end=" ") if eclipse==1: print("Blood",end=" ") print("Moon")
18th Sep 2018, 5:55 AM
JME
0
Ireneusz Rapa the last line will print("Moon") whether phase equals "Full" or not. Unless you have other thing to print within the else block e.g. print("Crescent") I don't see a need for else block in this case.
18th Sep 2018, 11:25 AM
Ipang
- 1
I need that else in case if phase not "Full" to print("Moon")
18th Sep 2018, 6:17 AM
Ireneusz Rapa
Ireneusz Rapa - avatar