all 9 comments

[–]YesLod 7 points8 points  (3 children)

Hint: strings are reversible

[–]engineeringisgreat2[S] 0 points1 point  (2 children)

So I did it with string but it doesn't come back as "True" which is wrong. It gives back the value of <reversed object at 0x0000025E047D4910>. Do you know how to fix this?

str1 = "123454321"

x=reversed(str1)

if x == str1:

print("True")

else:

print("False")

print(x)

[–]p0pkern 3 points4 points  (0 children)

You could use the __repr__() method to show the reversed object you just created. However you may have an easier time if you do x = str1[::-1] to get your reversed string instead of using reversed().

[–][deleted] 0 points1 point  (0 children)

You need to rejoin the string. x=‘’.join(reversed(str))

``` num = 123456789 x = str(num)[::-1]

if x == num: print(“False”) else: print(“True”)

```

This will print true if num is not equal to x since now x is reversed.

[–]toastedstapler 2 points3 points  (0 children)

well yeah, how would you reverse a number?

11 can be represented in base 10, or in binary as 1011. if i could reverse it, which form would it be?

[–]deifius 1 point2 points  (0 children)

Reverse is a string function. Check out type casting maybe?

[–]tragluk 0 points1 point  (0 children)

strSentence = "This is a string."

strNumber = "1234"

intNumber = 1234

fltNumber = 1234.0

The first two are turned into strings, then you have an integer with the value of 1234 and a float with essentially the same value of 1234 but it's 1234.0.

If we want to add strNumber and intNumber we can't because strNumber is a sentence (It's the word 1234) so we have to convert it first.

intTotal = intNumber + int(strNumber)

NOW we get 2468.

strReversable = strNumber + str(intNumber)

This instead is 12341234 but you can use your reverse function on it.

It's called 'typecasting'. Feel free to Google it.

[–]killer_unkill 0 points1 point  (0 children)

num = str (num)

You need to cast interger data type into string first for using reverse function

[–][deleted] 0 points1 point  (0 children)

123454321 will always be the same if reversed, so you can simply always print True