Home > database >  A workaround to converting a number to the same amount of hashtags?
A workaround to converting a number to the same amount of hashtags?

Time:09-11

Very new to programming so please forgive my ignorance:

number = int(input("Input the number of # you want."))
hashtag = 1
total = (number * hashtag)
while hashtag != total: 
print("#")
hashtag = hashtag   1

If i enter 4 for example, 3 hashtags will be printed, and i can't find an alternative so that i can display 4 hashtags instead.

CodePudding user response:

Python is a really cool language. You can write this in lots of ways. Here is a one liner:

number = int(input("Input the number of # you want."))
print("#" * number)

Another way with a for loop:

number = int(input("Input the number of # you want."))
for i in range(number):
    print("#", end="")  # end="" means no newline, print all in the same line

Another way with a while loop:

number = int(input("Input the number of # you want."))
counter = 0
while(counter != number):
    print("#", end="")
    counter  = 1

If you want a newline at the end of each #, add a '\n', like this

1st: print("#\n" * number)

2nd and 3rd: print("#") (just remove the end="")

CodePudding user response:

number = int(input("Input the number of # you want."))
print("#\n"*number)
  • Related