user2950162
user2950162

Reputation: 1011

check if a number ends up with either XX,5 or is an integer in python

I can solve it using multiple ifs and right function... but was wondering if there were a nicer solution...

as an example

10,5 would return true
10 would return true
9,3 would return false
9,5 would return true

Any ideas?

Upvotes: 0

Views: 65

Answers (1)

Kyle Strand
Kyle Strand

Reputation: 16499

Use regex:

import re
def int_or_comma_5(n):
    return re.match('\d+(,5)?$',n)

Upvotes: 2

Related Questions