Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print 'X' a number of times
#1
Hi What is wrong with my code? I'm trying to print the a number of 'X' strings based on my input value (integer). However, when I try to run it in my Python IDE, there is no output for some reason, nor do I get any error message. Any help or suggestion would be greatly appreciated.

numXs = int(input('How many times should I print the letter X? '))

toPrint = ''

while numXs >= 0:

    toPrint = numXs * 'X'

print(toPrint)
Reply
#2
numXs = int(input('How many times should I print the letter X? '))
print('X'*numXs)
result:
Output:
XXXXXXXXXX
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Print Player Name and Number of Pokemon webmanoffesto 1 1,109 Aug-23-2022, 08:54 PM
Last Post: deanhystad
  print two different sequence number mantonegro 2 1,669 Nov-16-2020, 06:19 PM
Last Post: mantonegro
  How to print string multiple times on new line ace19887 7 5,751 Sep-30-2020, 02:53 PM
Last Post: buran
  Print the number of items in a list on ubuntu terminal buttercup 2 1,950 Jul-24-2020, 01:46 PM
Last Post: ndc85430
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,747 Jun-18-2020, 04:59 PM
Last Post: QTPi
  How to print string multiple times separated by delimiter Mekala 1 1,900 May-23-2020, 09:21 AM
Last Post: Yoriz
  how do I make a number only print once but the number keeps on decreasing? syafiq14 5 2,968 Jan-03-2020, 10:34 AM
Last Post: perfringo
  BeautifulTable print header multi times evilcode1 11 5,142 Oct-29-2019, 11:53 AM
Last Post: buran
  How to list number of times element is in defaultdict and delete it mrapple2020 3 2,677 Apr-15-2019, 07:34 AM
Last Post: perfringo
  print number of a list line per line lateublegende 2 2,728 Mar-20-2019, 04:07 PM
Last Post: lateublegende

Forum Jump:

User Panel Messages

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