Python Forum
why is this variable not printing out properly?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why is this variable not printing out properly?
#1
Using python3 and am new - learning via introtopython.org and I'm having a problem.

var1 = (2+2)

print('The result of all calculations is ' + var1 + ' and we are done.')
Which returns the error of
Quote:Traceback (most recent call last):
  File "test.py", line 3, in <module>
    print('The result of all calculations is ' + var1 + ' and we are done.')
TypeError: Can't convert 'int' object to str implicitly

What am I doing wrong? When I change the variable to a string the line executes properly.
Reply


Messages In This Thread
why is this variable not printing out properly? - by dursland - Dec-27-2016, 07:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing the variable from defined function jws 7 1,543 Sep-03-2023, 03:22 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020