Python:Christmas Tree

2024/10/15 9:21:15

I need to print a Christmas tree that looks like this:

  /\  /  \
/    \

Here is my code so far:

for count in range (0,20):variable1 = count-20variable2 = count*2print('{0:{width1}}{1:{width2}}' .format('/','\\', width1=variable1 , width2=variable2))

I am using Python 3.5. And the coding says Sign not allowded in sstring format specifier

Answer
import builtins
builtins.unicode = str
print ('                  ',chr(0x2605))
for count in range (20):print ('{0:>{width1}}{1:>{width2}}' .format('/','\\', width1 = 20-count , width2 = 2*count+1))
print ('-----------------------------------------'
print ('                 [      ]                ')
print ('                 [      ]                ')
print ('                 [      ]                ')
print ('                 [      ]                ')
print ('                 [      ]                ')
print ('-----------------------------------------')

Thank You for the People that helped me FINISH!

https://en.xdnf.cn/q/117846.html

Related Q&A

Send back json to client side

I just started developing with cherrypy, so I am struggling a little bit. In client side I am selecting some data, converting it to json and sending to server side via post method. Then I am doing a fe…

Can I use PyInstaller from Python 2.7 to compile an executable for a Python 3 script?

So, I tried installing PyInstaller in my Python 3.4 dir but, for some reason, Ive been getting errors and Im not able to install it. I however, do have a working PyInstaller in my Python 2.7 dir. I nee…

exporting different lists to .txt in python

I have a few lists which I all want to export to the same .txt file. So far I only export 3 of the lists usingmy_array=numpy.array(listofrandomizedconditions) my_array2=numpy.array(inputsuser) my_arra…

Retrieving information from dictionary

Im having hard time trying to read my dictionary variable. Python keeps throwing the following error:TypeError: string indices must be integersThis is a sample that should give you an idea of what my p…

Python WMI Hyper-v GetSummaryInformation result

Im trying to retrieve information from all the available VMs on a Hyper-V Server. The problem is that when I ask for the summary information, i get a list of useless COMObjects.I cant find a way of get…

How to dynamically change variable name in form.vars.var_name

I have defined counter variable in controller.I can define tables and fields dynamically.tables = [db.define_table(example_table_%s % x,Field(example_field_%s % x, type=string, ...)...)for x in range(0…

Why will one loop modify a list of lists, but the other wont [duplicate]

This question already has answers here:Python list doesnt reflect variable change(6 answers)Closed 8 years ago.One of the answers in "python way" to parse and conditionally replace every elem…

Python CGI executable script downloads / shows script code

A script I wrote long ago (getWords.py) used to be executable at my localhost (http://local.example.com/getWords.py?query-string)My python script starts like this :#!/usr/bin/env python # chmod 755 ge…

My function returns None

I am new to Python and I was trying to solve this exercise, but keep getting None output. The question asked for a program in which the input is hours and rate and the output is the gross pay, includin…

Django undefined symbol: PyUnicode_AsUTF8

I am new to Python/Django. I have set up the environment needed to run Django project.When Im trying to migrate an existing project , it shows up this errordjango.core.exceptions.ImproperlyConfigured: …