Search Your Question...!

Problem -2

 Problem Statement:

Arpasland has surrounded by attackers. A truck enters the city. The driver claims the load is food and medicine from Iranians. Ali 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 not.

We consider the letters "A","E","I","O","U","Y" to be vowels for this problem.

Input Format

The first line contains a string of length 9. The format is "DDXDDD-DD", where D stands for a digit (non zero) and X is an uppercase english letter.

Output Format

Print "valid" (without quotes) if the tag is valid, print "invalid" otherwise (without quotes)

Sample Input

12X345-67

Sample Output

invalid

Explanation

The tag is invalid because the sum of first and second digit of it is odd (also the sum of 4'th and 5'th, 5'th and 6'th and 8'th and 9'th are odd).


# Write your code here

# Write your code here

Tag = input()                  # Reading input from STDIN

#Cond1 checking the charachter

cond1= (Tag[6] == "-" and (not "0" in Tag) and Tag[0].isdigit() and Tag[1].isdigit() and Tag[3].isdigit() and Tag[4].isdigit() and Tag[5].isdigit() and Tag[7].isdigit() and Tag[8].isdigit() and Tag[2].isupper() and not (Tag[2] in {"A","E","I","O","U"}))

#Cond2 checking sum of consecutive digits is even

cond2=((int(Tag[0])+int(Tag[1]))%2==0 and (int(Tag[3])+int(Tag[4]))%2==0 and (int(Tag[4])+int(Tag[5]))%2==0 and (int(Tag[7])+int(Tag[8]))%2==0)

if cond1:

    if cond2:

        print("valid")          # Writing output to STDOUT

    else:

        print("invalid")         # Writing output to STDOUT 

else:

    print("invalid")              # Writing output to STDOUT

OUTPUT:

Example1:



Example2:



1 comment: