使我的打印输出显示在同一行

时间:2015-11-05 22:04:12

标签: python python-3.x

number=int(input("Input a positive number less than 100:"))
perfect=1
for perfect in range (1,number):
    a=perfect*perfect
    if a >= number:
        break
    print (a)

将输出:

Input a positive number less than 100:81
1
4
9
16
25
36
49
64

但它会在一个单独的行上完成这些

如何制作它们以便在同一行上打印?

2 个答案:

答案 0 :(得分:0)

使用end函数中的print参数:

print(..., end=" ")

答案 1 :(得分:0)

This is what you are looking for

print(a, end=" ") # Appends a space instead of a newline
相关问题