repl.it
@SagaciousPan/

Odd and Even number separator

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
###Imported libraries###
import replit
import re

###Initalize variables###
#Regular Expression to match ODD numbers
regex1 = re.compile ('\d*[13579]')
#Regular Expression to match EVEN numbers
regex2 = re.compile ('\d*[02468]')
#Regular Expression to match numbers seperated by ',' or ';'
regex3 = re.compile ('(\d+(,|;))+')
numbers = None

#Find out thier number and set it to the variable "number"
while (numbers == None):
  replit.clear()
  print ("""What's your number list?
Example: "1,2,3,4,5,6,7,8,9,10;"
Make sure the number is seprated by ',' and ends with ';'.""")
  testNumber = input(">")
  if (regex3.match(testNumber) != None):
   numbers = testNumber

#print your number list
print ("\nYour number list:\n%s\n" % numbers)

#print an actual list of numbers
#of the even numbers that were in your list
evenNumberList = regex2.findall(numbers)
print ("An actual list of numbers,\nThe EVEN numbers within your list:\n")
print ("%s\n" % evenNumberList)


#print an actual list of numbers
#of the even numbers that were in your list
oddNumberList = regex1.findall(numbers)
print ("An actual list of numbers,\nThe ODD numbers within your list:\n")
print ("%s\n" % oddNumberList)

nE = len(evenNumberList)
print ("Number of EVENS: %s" % nE)
nO = len(oddNumberList)
print ("Number of ODDS: %s" % nO)