Convert to python please. Thanks! import java.util.ArrayList; import java.util.Arrays; public class StretchWith2Vowels

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Convert to python please. Thanks! import java.util.ArrayList; import java.util.Arrays; public class StretchWith2Vowels

Post by answerhappygod »

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;
}
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply