Python Forum

Full Version: Unable to combine print statements in for loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am learning Python on my own. I am using Python Crash Course by Eric Matthes. Chapter 4: Looping through a Slice -

#my list
players = ['charles', 'martina', 'michael', 'florence', 'eli']

#my instruction is to print out the first three players names of the team using a for loop. Book lays out the format like this;
print("Here are the first three players on my team:")
for player in players[:3]:
    print(player.title())
#my output should be
Output:
Here are the first three players on my team: Charles Martina Michael
#I am using Python 3.8.1 Shell and I am unable to figure out how to combine both print statements to read as the output. When I type the first print statement and hit enter, it prints before I can enter the for loop information.

How do I get the output that the book says that I should expect?
it looks like you are entering your code in python interactive shell. that is when you have >>> at the start of the line. In this mode every line is evaluated and executed immediately.
You need to write your code in a file and save it as file with py extension and then execute it.

Look at https://python-forum.io/Thread-How-to-Ex...ython-code for more info
Thank you for your help.