Created
June 25, 2021 14:56
-
-
Save Just-Simple-59/aa9d6de30225b4c69c877bc68b178dd3 to your computer and use it in GitHub Desktop.
Considering integers and alphabets in a list and solving a given condition.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Date: 25/06/2021 Time: 12:12pm | |
# Question: Arpasland has surrounded by attackers. A truck enters the city. The driver claims the load | |
# is food and medicine from Iranians.Arun is one of the soldiers in Arpasland. He doubts about | |
# the truck, maybe it's from the siege. He knows that a tag is valid if the sum of every two | |
# consecutive digits of it is even and its letter is not a vowel. | |
# Determine if the tag of the truck is valid or invalid. | |
# Consider the letters A, E, I, O, U, Y to be vowels for this problem. | |
tag = input("Enter the tag\n") | |
number = [] | |
word = [] | |
vowels = 'aeiouy' | |
for element in list(tag): | |
if element.isdigit(): | |
number.append(int(element)) | |
for element in list(tag): | |
if element.isalpha(): | |
word.append(element) | |
word = ' '.join(map(str, word)).lower() | |
res = [a + b for a, b in zip(number, number[1:] + [number[0]])] # overlaping sum of consecutive operation is considered | |
for element in res: | |
if element % 2 == 0: | |
continue | |
else: | |
print("the tag is invalid") | |
exit() | |
if word not in vowels: | |
print("The tag is valid") | |
else: | |
print("The tag is invalid") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment