Skip to main content
added 86 characters in body
Source Link
Blauelf
  • 21k
  • 2
  • 13
  • 22

What is wrong with my second For Loop (spaces)? It seems like it only runs one time, according to the first line of the pyramid.

import cs50

while True: print("Type a number between 0 and 23: ", end="") n = cs50.get_int() if n > 0 or n < 23: break i=0 spaces = n - 1 for i in range(i,n,+1): for spaces in range(spaces,0,-1): print(" ", end="") spaces = spaces - 1 print("#" * (i+2), end="") print()

import cs50

while True:
    print("Type a number between 0 and 23: ", end="")
    n = cs50.get_int()
    if n > 0 or n < 23:
        break
i=0
spaces = n - 1
for i  in range(i,n,+1):
    for spaces  in range(spaces,0,-1):
        print(" ", end="")
    spaces = spaces - 1
    print("#" * (i+2), end="")
    print()

Results Type a number between 0 and 23: 5 ##

 
Type a number between 0 and 23: 5
    ##
###
####
#####
######

What is wrong with my second For Loop (spaces)? It seems like it only runs one time, according to the first line of the pyramid.

import cs50

while True: print("Type a number between 0 and 23: ", end="") n = cs50.get_int() if n > 0 or n < 23: break i=0 spaces = n - 1 for i in range(i,n,+1): for spaces in range(spaces,0,-1): print(" ", end="") spaces = spaces - 1 print("#" * (i+2), end="") print()

Results Type a number between 0 and 23: 5 ##

 

What is wrong with my second For Loop (spaces)? It seems like it only runs one time, according to the first line of the pyramid.

import cs50

while True:
    print("Type a number between 0 and 23: ", end="")
    n = cs50.get_int()
    if n > 0 or n < 23:
        break
i=0
spaces = n - 1
for i  in range(i,n,+1):
    for spaces  in range(spaces,0,-1):
        print(" ", end="")
    spaces = spaces - 1
    print("#" * (i+2), end="")
    print()

Results

Type a number between 0 and 23: 5
    ##
###
####
#####
######
Source Link
user13767
user13767

CS50 2017 Problem Set 6 Mario.py For loop

What is wrong with my second For Loop (spaces)? It seems like it only runs one time, according to the first line of the pyramid.

import cs50

while True: print("Type a number between 0 and 23: ", end="") n = cs50.get_int() if n > 0 or n < 23: break i=0 spaces = n - 1 for i in range(i,n,+1): for spaces in range(spaces,0,-1): print(" ", end="") spaces = spaces - 1 print("#" * (i+2), end="") print()

Results Type a number between 0 and 23: 5 ##