Forgot to post my soution from yesterday, also in Python:
importsysdefchristmas_tree(height):'''
Outputs a Christmas tree of the correct height.
'''try:height=int(height)except:raiseTypeError('Height must be of type int. Actual type: {}'.format(type(height)))ifheightisNoneorheight<1orheight>100:raiseValueError('Height must contain a value greater than 0')level=0whilelevel<height:stars='*'*calculate_num_of_stars(level)stars=stars.center(height*2)print(stars)level+=1defcalculate_num_of_stars(level):'''
Calculates the correct number of stars that must be output.
'''return2*(level+1)-1iflen(sys.argv)>1:height=sys.argv[1]print(christmas_tree(height))
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Forgot to post my soution from yesterday, also in Python: