diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-08 21:15:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-08 21:15:27 +0100 |
| commit | c27f53ea3c7c6b8cd8a30c6ecb4894364e07f6ec (patch) | |
| tree | 11a5d24647d3f330f797a4feceb591051619b926 /challenge-053/paulo-custodio/python/ch-2.py | |
| parent | 316afc1486285c67d08f4a6899f69c1baaae95bf (diff) | |
| parent | 451d779420e30ac64a61beadea91da317b8dc6b2 (diff) | |
| download | perlweeklychallenge-club-c27f53ea3c7c6b8cd8a30c6ecb4894364e07f6ec.tar.gz perlweeklychallenge-club-c27f53ea3c7c6b8cd8a30c6ecb4894364e07f6ec.tar.bz2 perlweeklychallenge-club-c27f53ea3c7c6b8cd8a30c6ecb4894364e07f6ec.zip | |
Merge pull request #10794 from pauloscustodio/master
Add Python solutions
Diffstat (limited to 'challenge-053/paulo-custodio/python/ch-2.py')
| -rw-r--r-- | challenge-053/paulo-custodio/python/ch-2.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/challenge-053/paulo-custodio/python/ch-2.py b/challenge-053/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..2672f2d84a --- /dev/null +++ b/challenge-053/paulo-custodio/python/ch-2.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +# Challenge 053 +# +# TASK #2 +# Vowel Strings +# Write a script to accept an integer 1 <= N <= 5 that would print all possible +# strings of size N formed by using only vowels (a, e, i, o, u). +# +# The string should follow the following rules: +# +# 'a' can only be followed by 'e' and 'i'. +# +# 'e' can only be followed by 'i'. +# +# 'i' can only be followed by 'a', 'e', 'o', and 'u'. +# +# 'o' can only be followed by 'a' and 'u'. +# +# 'u' can only be followed by 'o' and 'e'. +# +# For example, if the given integer N = 2 then script should print the following +# strings: +# +# ae +# ai +# ei +# ia +# io +# iu +# ie +# oa +# ou +# uo +# ue + +import sys + +def show_vowels(n, string): + if len(string) == n: + print(string) + elif string == "": + for vowel in ['a', 'e', 'i', 'o', 'u']: + show_vowels(n, string+vowel) + elif string[-1] == 'a': + for vowel in ['e', 'i']: + show_vowels(n, string+vowel) + elif string[-1] == 'e': + for vowel in ['i']: + show_vowels(n, string+vowel) + elif string[-1] == 'i': + for vowel in ['a', 'e', 'o', 'u']: + show_vowels(n, string+vowel) + elif string[-1] == 'o': + for vowel in ['a', 'u']: + show_vowels(n, string+vowel) + elif string[-1] == 'u': + for vowel in ['e', 'o']: + show_vowels(n, string+vowel) + else: + print("expected vowel, got "+string) + +n = int(sys.argv[1]) +show_vowels(n, "") |
