From 95154be03505c7f8108b5419139eeb6b112f23fa Mon Sep 17 00:00:00 2001 From: Abraham Albert Date: Mon, 3 Jul 2017 04:06:40 +0530 Subject: [PATCH 1/2] All the 4 Digit Number Combinations It'll print every 4 digit combination from 0000 to 9999. These are used in many real world applications. --- 4 Digit Number Combinations.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 4 Digit Number Combinations.py diff --git a/4 Digit Number Combinations.py b/4 Digit Number Combinations.py new file mode 100644 index 00000000000..93f0a1a6176 --- /dev/null +++ b/4 Digit Number Combinations.py @@ -0,0 +1,18 @@ +#ALL the combinations of 4 digit combo +def FourDigitCombinations(): + numbers=[] + for code in range(10000): + if code<=9: + numbers.append(int("000"+str(code))) + elif code>=10 and code<=99: + numbers.append(int("00"+str(code))) + elif code>=100 and code<=999: + numbers.append(int("0"+str(code))) + else: + numbers.append(int(code)) + + for i in numbers: + print str(i), + + pass + From 8d3874f4697711d65302c69c155b4146b7a3b74b Mon Sep 17 00:00:00 2001 From: Abraham Albert Date: Mon, 3 Jul 2017 20:01:00 +0530 Subject: [PATCH 2/2] Update 4 Digit Number Combinations.py Used zfill() function now. --- 4 Digit Number Combinations.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/4 Digit Number Combinations.py b/4 Digit Number Combinations.py index 93f0a1a6176..6ac4ab93327 100644 --- a/4 Digit Number Combinations.py +++ b/4 Digit Number Combinations.py @@ -3,16 +3,20 @@ def FourDigitCombinations(): numbers=[] for code in range(10000): if code<=9: - numbers.append(int("000"+str(code))) + code=str(code) + numbers.append(code.zfill(4)) elif code>=10 and code<=99: - numbers.append(int("00"+str(code))) + code=str(code) + numbers.append(code.zfill(4)) elif code>=100 and code<=999: - numbers.append(int("0"+str(code))) + code=str(code) + numbers.append(code.zfill(4)) else: - numbers.append(int(code)) + numbers.append(str(code)) for i in numbers: - print str(i), - + print i, + pass +