python - Why is my python Mario program less comfortable ignoring the spaces?
问题描述
I'm working on cs50 pset6 python Mario, and it's supposed to take an int as input (the int is named height) and then make a mario pyramid of size(height), like this:
$ python mario.py
Height: 4
#
##
###
####
But my program prints this:
~/ $ python mario.py
Height: 4
#
##
###
####
I don't know why. Here's my code:
from cs50 import get_int
height = get_int("Height: ")
while height < 1 or height > 8:
height = get_int("Height:")
for i in range(1, height+1):
for j in range(height - i):
print("", end = '')
if i == 1:
print("#")
if i == 2:
print("##")
if i == 3:
print("###")
if i == 4:
print("####")
if i == 5:
print("#####")
if i == 6:
print("######")
if i == 7:
print("#######")
if i == 8:
print("########")
If you find my bug, please tell me. Thanks.
解决方案
It looks like you are printing an empty string instead of white spaces:
print("", end = '')
Try this instead:
print(" ", end = '')
推荐阅读
- php - 如何使用此结构创建不重复的数组
- c# - 如何从网格控件中删除选定的行
- javascript - 如何合并两个 blob 音频和视频并获得一个视频 blob 对象
- c++ - 简单地包括
导致链接错误 - python - 由 pyinstaller 创建的 exe 文件:scipy 'list' object has no attribute 'join' 问题
- c - 即使在向其中添加元素后,链表也总是为 NULL
- swift - 如何将 [UIImage] 存储到 Core Data 并从二进制日期检索到 [UIImage]
- node.js - 繁琐和续集之间的区别
- python - 如何动态设置小部件的大小和填充以适应 Tkinter 中的窗口?
- javascript - 如何将对象添加到 Knex 中的数据库中,其中该对象是两个父母的孩子?