Python Forum
Unable to combine print statements in for loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to combine print statements in for loop
#1
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?
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you for your help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print statements without () petec 7 1,989 Jun-17-2022, 02:27 AM
Last Post: snippsat
  Multiple Loop Statements in a Variable Dexty 1 1,198 May-23-2022, 08:53 AM
Last Post: bowlofred
  Unable to Loop Over Date gdbengo 2 1,287 Jan-09-2022, 05:11 PM
Last Post: menator01
Exclamation question about input, while loop, then print jamie_01 5 2,648 Sep-30-2021, 12:46 PM
Last Post: Underscore
  why print('\n') produced 2 new lines instead of 1 - Located inside a FOR loop JulyFire 2 2,514 Jan-10-2021, 01:50 AM
Last Post: JulyFire
  Unable to print stuff from while loop Nick1507 4 2,323 Sep-17-2020, 02:26 PM
Last Post: Nick1507
  Print output in single file using pramika loop deepakkhw 1 2,064 Jul-11-2020, 11:57 AM
Last Post: j.crater
  Create, assign and print variables in loop steven_tr 10 4,330 May-28-2020, 04:26 PM
Last Post: ndc85430
  Print different positions in loop from functions konsular 5 2,697 Oct-16-2019, 08:10 PM
Last Post: buran
  Unable to execute the for loop harold 1 1,726 Sep-23-2019, 12:27 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020