+ 2

how can i right a program for giving me staras?

A program that gets an input as int like n if n>=3 it gives me a triangle of stars for example when n=6 the out put is * ** *** **** ***** ****** ***** **** *** ** *

1st Nov 2020, 8:46 AM
shahrbanoogolmohamadi
3 Antworten
+ 2
banoo use stars(num) only When you are using print inside a function and not returning any value, using print(stars(num)) returns none
1st Nov 2020, 4:37 PM
Abhay
Abhay - avatar
+ 3
for i in range(1,6+1): print(i*"*") for i in range(6-1,0,-1): print(i*"*")
1st Nov 2020, 8:56 AM
Abhay
Abhay - avatar
+ 3
Abhay thanks for your help I wrote this and it works but I dont understand why at the end it shows None How can I avoid this? def stars(n): if n>=3: for i in range(1,(n+1)): print (i*"*") for i in range((n-1),0,-1): print(i*"*") num=int(input("type a number:") print(stars(num)) >>> type a number:3 >>> * ** *** ** * None
1st Nov 2020, 3:14 PM
shahrbanoogolmohamadi