Python Forum
question about input, while loop, then print
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
question about input, while loop, then print
#4
Another way

names = []
counter = 1

while True:
    name = input('Enter Name: ')
    if name == 'q':
        break

    names.append(f'{counter}. {name}')
    counter += 1

    for name in names:
        print(name)
Output:
Enter Name: john 1. john Enter Name: jane 1. john 2. jane Enter Name: sue 1. john 2. jane 3. sue Enter Name: bob 1. john 2. jane 3. sue 4. bob
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: question about input, while loop, then print - by menator01 - Sep-28-2021, 09:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,359 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  Code won't break While loop or go back to the input? MrKnd94 2 1,157 Oct-26-2022, 10:10 AM
Last Post: Larz60+
  Question: print issue python202209 3 1,090 Sep-18-2022, 11:51 AM
Last Post: jefsummers
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,654 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  input function question barryjo 12 3,096 Jan-18-2022, 12:11 AM
Last Post: barryjo
Big Grin General programming question (input string)[ jamie_01 2 1,747 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
  A question about 'Event loop is closed' fc5igm 2 2,455 Oct-05-2021, 02:00 AM
Last Post: fc5igm
  why print('\n') produced 2 new lines instead of 1 - Located inside a FOR loop JulyFire 2 2,701 Jan-10-2021, 01:50 AM
Last Post: JulyFire
  I want to check if the input is str or is int & if it's str repeat the loop HLD202 4 2,955 Nov-23-2020, 11:01 PM
Last Post: perfringo
  Loop back through loop based on user input, keeping previous changes loop made? hbkpancakes 2 3,081 Nov-21-2020, 02:35 AM
Last Post: hbkpancakes

Forum Jump:

User Panel Messages

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