Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python
# Caden McKinney
# 7/1/18
# Unit6_Practice
# Output back to the user an alphabetized list of only the names with even or odd number of letters


FriendsNames = []
Even = []
Odd = []

while True:
       Name = raw_input("Input Your Friends Names (Press Enter Again at The End To Confirm): \n")
       if Name == "":
              break
       else:
              FriendsNames.append(Name)
for name in FriendsNames:
       Length = len(name)
if FriendsNames[1] == (Length % 2 == 0):
       Even.append(FriendsNames[1])
else:
       Odd.append(FriendsNames[1])
if FriendsNames[2] == (Length % 2 == 0):
       Even.append(FriendsNames[2])
else:
       Odd.append(FriendsNames[2])
if FriendsNames[3] == (Length % 2 == 0):
       Even.append(FriendsNames[3])
else:
       Odd.append(FriendsNames[3])
if FriendsNames[4] == (Length % 2 == 0):
       Even.append(FriendsNames[4])
else:
       Odd.append(FriendsNames[4])
if FriendsNames[5] == (Length % 2 == 0):
       Even.append(FriendsNames[5])
else:
       Odd.append(FriendsNames[6])
if FriendsNames[6] == (Length % 2 == 0):
       Even.append(FriendsNames[6])
else:
       Odd.append(FriendsNames[6])
if FriendsNames[6] == (Length % 2 == 0):
       Even.append(FriendsNames[6])
else:
       Odd.append(FriendsNames[6])
print FriendsNames.sort()
print FriendsNames
for name in FriendsNames:
       Length = len(name)
       print(name + " is " + str(Length) + " characters long.")
if Name == "":
       print("\n")
       
       Input = raw_input("Do you want the Even or Odd Names?\n" )
       if Input == "Even":
              print(Even)
       elif Input == "Odd":
              print(Odd)


What I have tried:

What am I doing wrong? Need the input to go to even list or odd list and everything is going into odd.
Posted
Updated 8-Jan-18 14:15pm
v2
Comments
Patrice T 8-Jan-18 19:37pm    
Format your code with 'code' button.
select code
over with mouse on 'code' button
click on Python in drop list
PIEBALDconsult 8-Jan-18 19:56pm    
Because it's doing exactly what you told it to do.

1 solution

You should study what this code is doing, what it means, I gear ot is not what you expect.
Python
FriendsNames[1] == (Length % 2 == 0)

Looks like you don't really understand what your code is doing, use the debugger to see what it really does.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]
27.3. pdb — The Python Debugger — Python 3.6.1 documentation[^]
Debugging in Python | Python Conquers The Universe[^]
pdb – Interactive Debugger - Python Module of the Week[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900