-4

I want to make a pyramid but there is a new line after every for loop. This is worked example 12.01 in the CAIE A-Level Textbook.

maxnumber = 2
numberofspaces = 0
numberofsymbols = 1
# Set values
symbol = input("Enter a symbol.\n")
while maxnumber % 2 == 0:
    maxnumber = int(input("Enter the number of symbols you want in the base.\n"))
numberofspaces = int((maxnumber - 1) / 2)
while numberofsymbols <= maxnumber:
    for space in range(numberofspaces):
        print(" ")
    for i in range(numberofsymbols):
        print(symbol)
    print("\n")
    numberofsymbols += 2
    numberofspaces -= 1

Expected results-

  $
 $$$
$$$$$

Actual results-

$



$
$
$


$
$
$
$
$
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135

1 Answers1

4

If you don't want new line, simply add new argument end=''

print(symbol,end='')
Mert Köklü
  • 2,183
  • 2
  • 16
  • 20