Skip to content

Instantly share code, notes, and snippets.

@kaito834
Created July 18, 2015 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaito834/d43aea041a2bd2c056c9 to your computer and use it in GitHub Desktop.
Save kaito834/d43aea041a2bd2c056c9 to your computer and use it in GitHub Desktop.
Split str by comma, and validate the str whether those are decimal between 0 and 10
#!/usr/bin/env python
# tested by Python 3.4.3 on Windows 8.1
# Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
def main():
numbers = []
str = input('Please input numbers separated by comma: \n> ')
# https://docs.python.org/3/library/stdtypes.html#string-methods
# p.87, 4.2.5 リストのメソッド, ”Python文法詳解", O'REILLY
for n in str.split(','):
n = n.strip()
if(n.isdecimal() and 0 <= int(n) <= 10 and numbers.count(int(n)) == 0):
numbers.append(int(n))
for n in numbers:
print(n)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment