Python prob

0 DIPAK CHAPAGAIN · August 4, 2015
a="['kathmandu']"
print(a)
b=input("yr word")
c="['"+b+"']"
print(c)
if c is a:
print("ur good")
else:
print("ur mistaken")

The result's
 
C:\Python34\python.exe C:/Users/DIPAK/PycharmProjects/untitled2/try.py
['kathmandu']
yr wordkathmandu
['kathmandu']
ur mistaken

Process finished with exit code 0

Post a Reply

Replies

Oldest  Newest  Rating
0 Otto Von Chesterfield · August 9, 2015
First, try to put your code in blocks like these:
a="['kathmandu']"
print(a)
b=input("yr word")
c="['"+b+"']"
print(c)
if c is a:
print("ur good")
else:
print("ur mistaken")

It makes things a whole lot easier to understand.

Next, the "is" keyword checks to see if c and a are the same objects. While they both represent the same value, they began in different ways. Instead, use the '==' operator. I've tried it and it works.

The reason it works is because the '==' operator calls the object's __equ__ method. This method checks to see if c and a have the same values (aka. they both say "['kathmandu']").
  • 1

Python

106,940 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator