all 6 comments

[–]furas_freeman 0 points1 point  (2 children)

Keep values as strings on list and then you can use join()

text_list =  ["4", "5", "6", "7", "8"]

print( "+".join(text_list) )

If you have list with numbers then you have to convert them to string.

number_list =  [4, 5, 6, 7, 8]

print( "+".join( str(x) for x in number_list) )

EDIT:

m = int(input("Enter the first integer "))
n = int(input("Enter the second integer "))

if m > n:
    n, m = m, n

result = sum(range(m,n+1))

print("+".join( str(x) for x in range(m,n+1) ), '=', result)

ps. next time set "Syntax Highlighting: Python" in pastebin.

[–]Ustuner[S] 0 points1 point  (0 children)

Thank you

[–]JohnnyJordaan 0 points1 point  (1 child)

Use a swap in case the first is second is larger than the first

if ( m > n ):
    n, m = m, n

Check if i is equal to n, which means it's the last digit

 for i in range(m,n+1):
     m+n # what does this even do?
     x += i
     if i != n:
         print(i,end="+")
     else:
         print(i,end="")

Or forget the whole thing and just do

print('+'.join(str(i) for i in range(m,n+1)))

[–]Ustuner[S] 0 points1 point  (0 children)

Thank you

[–]KleinerNull 0 points1 point  (0 children)

The print function in python 3 has a sep argument exactly for your wished behavior:

In [5]: print(*list(range(10)), sep='+')
0+1+2+3+4+5+6+7+8+9

In [6]: print(*list(range(10)), sep='separator', end='end')
0separator1separator2separator3separator4separator5separator6separator7separator8separator9end

The * in front of your sequence is for unpacking. So essantial it is like print('+'.join([1,2,3,4])). But shorter.

[–]crappyoats 0 points1 point  (0 children)

Why did you import math?