Convert to python please. Thanks!
import java.util.ArrayList;
import java.util.Arrays;
public class StretchWith2Vowels {
private static ArrayList<Character> vowels =
new ArrayList<Character>();
public static boolean check(String word) {
int numVowels = 0;
char[] chars =
word.toCharArray();
for (Character c : chars) {
if (c == 'z' || c == 'Z')
{
if
(numVowels == 2) {
return true;
}
numVowels =
0;
continue;
} else {
if
(vowels.contains(c)) {
numVowels++;
}
}
}
if (numVowels == 2) {
return true;
} else {
return false;
}
}
public static void main(String[] args) {
String input = "";
vowels.addAll(Arrays.asList('a', 'e',
'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));
int stretch = 0;
while (true) {
System.out.print("Sentence: ");
input =
In.nextLine();
if (input.equals("*"))
{
System.out.println("Done");
return;
}
String[] words =
input.split(" ");
for (String s : words)
{
if
(check(s)) {
stretch++;
}
}
System.out.println("Matching words = " + stretch);
stretch = 0;
}
}
}
Convert to python please. Thanks! import java.util.ArrayList; import java.util.Arrays; public class StretchWith2Vowels
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am