简体   繁体   中英

Similar code but doesn't work

n = int(input())
for i in range(1, n+1):
    print("%s%s" % (" "*i, "*"*(n-i))

This code works well. And this is the output.

    *
   **
  ***
 ****
*****

I want to change it upside down. So I tried like that.

for i in range(1, n+1):
    print("%s%s" % (" "*i, "*"*(n-i))

But it doesn't work and even is not compiled.

You are missing an ) :

print("%s%s" % (" "*i, "*"*(n-i)))

You got three ( but only 2 ) . Adding the last one should work. Try it here!

Example output:

 ****
  ***
   **
    *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM