Issue
Animals = ('Lion', 'Fox', 'Deer', 'Moose',
'Crocodile', 'Camel', 'Horse', 'Cow',
'Rabbit', 'Peacock', 'Hummingbird', 'Zebra',
'Armadillo', 'Tiger', 'Giraffe', 'Turtle',
'Elephant', 'Snake', 'Lizard', 'Wolf',
'Alligator', 'Sheep', 'Cheetah', 'Rattlesnake',
'Frog', 'Raccoon', 'Coyote', 'Goat',
'Panda', 'Toad', 'Pig', 'Cobra',
'Kangaroo', 'Salamander', 'Skunk', 'Chicken',
'Anaconda', 'Koala', 'Octopus', 'Otter',
'Duck', 'Python', 'Rhinoceros', 'Polar', 'bear',
'Gorilla', 'Hippopotamus', 'Lobster', 'Crab',
'Jellyfish', 'Seahorse', 'Platypus', 'Koala',
'Hedgehog', 'Mole', 'Hawk', 'Falcon',
'Turkey', 'Eagle', 'Starfish', 'Clam',
'Garter snake', 'Kingfisher', 'Dolphin', 'Whale',
'Grizzly bear', 'Chimpanzee', 'Ant', 'Spider',
'Butterfly', 'Bee', 'Chimpanzee', 'Gorilla',
'Tasmanian Devil', 'Dingo', 'Penguin', 'Sparrow',
'Owl', 'Parrot', 'Whale', 'Shark',
'Dolphin', 'Otter', 'Pigeon', 'Stingray',
'Shark', 'Penguin', 'Swan', 'Eel',
'Scorpion', 'Bat', 'Ostrich', 'Squirrel',
'Orangutan', 'Lemur', 'Sloth', 'Flamingo',)
answer = input('animal name:')
if answer in Animals:
print('correct')
else:
print('wrong its not an animal!')
If user input an animal's name with lowercase it print's 'wrong its not an animal!' Tell the easier way to solve this problem
Solution
You can save the strings as lowercase by default:
animals = ('dion', 'dox', 'deer')
Then change your input code to convert to lowercase before checking against the tuple:
if answer.lower() in animals:
print('correct')
else:
print('wrong its not an animal!')
If you still need strings starting with capital letter, use str.capitalize()
Answered By - Quasy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.