May-14-2017, 07:56 PM
(May-14-2017, 07:39 PM)Stefython Wrote: I'm brand new to programming, busy practicing some coding. What am I doing wrong here?
>>>farm_equipment = ["jd r4038", "jd 9620", "jd 9630", "jd 4455", "jd 6140d", "jd 9860", "jd 9870", "jd seeder"]
>>>message_c = "\nList of current equipment: "
>>>print(message_c + farm_equipment)
I'm getting the following error:
Traceback (most recent call last):
File "every_function_c3.py", line 17, in <module>
print(message_c + farm_equipment)
TypeError: must be str, not list
You are trying to add incompatible types - string and list. You can print either directly - though in case of list it may look strange to you.
In order to concatenate, you have to convert list to string - one of the usual methods is to
join
itprint(message_c + ', '.join(farm_equipment))
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.