if city == 'Chennai':
print "this is Chennai city"
elif city == 'Delhi':
print "this is Delhi city"
else:
print "invalid city"
I want to raise ValueError whenever city is invalid. How to do that ?
city = 'some city'
if city == 'Pune':
print "this is pune city"
elif city == 'Delhi':
print "this is Delhi city"
else:
raise ValueError("Invalid City")
Traceback (most recent call last):
File "<pyshell#2>", line 8, in <module>
raise ValueError('Invalid City')
ValueError: Invalid City
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With