Question

I am using Python 3.5.2 2. Create a function called is_interesting that, given a string, returns...

I am using Python 3.5.2

2. Create a function called is_interesting that, given a string, returns the Boolean value True if the number of vowels (a e i o u) in the string is a prime number (assume that the strings are always passed as lower-case letters to simplify). The function header should be as follows: def is_interesting(a_string) For example is_interesting(“yien”) returns True, is_interesting(“wang”) returns False

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def is_interesting(a_string):
count = 0
for i in range(0, len(a_string)):
ch = a_string[i]
if ch == 'a' or ch =='i' or ch == 'e' or ch == 'o' or ch == 'u':
count = count + 1
if isPrime(count):
return True;
else:
return False;
  
def isPrime(n):
if n < 2:
return False;
for i in range(2, n/2):
if n % i == 0:
return False;
return True;
     
  
  
print is_interesting("yien");
print is_interesting("wang");
print is_interesting("Suresh");

Output:

sh-4.3$ python main.py                                                                                                                                                                                                                                 

True                                                                                                                                                                                                                                                   

False                                                                                                                                                                                                                                                  

True

Add a comment
Know the answer?
Add Answer to:
I am using Python 3.5.2 2. Create a function called is_interesting that, given a string, returns...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function called most_consonants(words) that takes a list of strings called words and returns the...

    Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...

  • python function will Return True if string x contains 3 vowels in a row, in consecutive...

    python function will Return True if string x contains 3 vowels in a row, in consecutive locations, false otherwise. assuming that 'vowels' refer to the following lowercase lttrs: a,e,i,o,u programs fails partially, only allowed to use float, str, int, appen, split, strip, len, range def vowels_three(x): for i in range (o, len(x), 2): if x[i] not in ('a,e,i,o,u'): return False return True

  • Using python, create a program using nested loops to write a function called substring(s,b) that returns...

    Using python, create a program using nested loops to write a function called substring(s,b) that returns True or False depending on whether or not b is a substring of s. For example: String: "Diamond" Substring: "mond" The code will then state that this is true and "mond" is a substring of "Diamond". Example of what the program should output: Enter string: Tree Enter substring: Tre Yes, 'Tre' is a substring of 'Tree' Limitation: This program cannot use "find()" and "in"...

  • I need help writing this function in python. Write a function that takes, as input and...

    I need help writing this function in python. Write a function that takes, as input and returns a dictionary where each string in L is a key and the vowels of the string are values. This function is called def dictVowel(L). sample input is ["one", "two", "three"] output will be {"one": "oe", "two": "o", "three": "ee"}

  • Python 3: Write a function called every_other_character() that takes in a string and returns a new...

    Python 3: Write a function called every_other_character() that takes in a string and returns a new string with every other character removed. That is, the new string will include the first, third, fifth, etc. letters of the given string. Must use a while or for loop in the solution.

  • Create a Python script file called hw.py. Then import the module random: from random import *...

    Create a Python script file called hw.py. Then import the module random: from random import * Thanks in advance! Ex. 1. Write a function called cleanLowerWord that receives a string as a paramcter and retums a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this,...

  • python Problem 3 (Palindrome) Write a function called ispalindrome(string) that takes a string (with spaces) as...

    python Problem 3 (Palindrome) Write a function called ispalindrome(string) that takes a string (with spaces) as argument and returns True if that string (ignoring spaces) is a palindrome. A palindrome is a word or phrase that spells the same thing forwards as backwards (ignoring spaces). Your program should use a recursive process to determine the result, by comparing the first and last letters of the string, and if necessary, calling ispalindrome() on the rest of the string. Sample run: print(ispalindrome('never...

  • Python Programming Assignment: Write a function to take a string S that returns True if the...

    Python Programming Assignment: Write a function to take a string S that returns True if the letters are in ascending order and False otherwise. To do this go over each letter and check that it is less than the letter that precedes it. Then write a function main that gets one input from the user, then if passing that input to the function above returns True, then show "String is in order", otherwise show " String is unordered".

  • In Python Create a function called sum_string ( csv_string ) Where csv_string is a string of...

    In Python Create a function called sum_string ( csv_string ) Where csv_string is a string of comma - separated values. integer that is the sum of the numerical values in the string It returns an Example: sum_string("11,22,33") Return 66

  • In Python: Implement the function is_number() that returns True if the input is a number and...

    In Python: Implement the function is_number() that returns True if the input is a number and otherwise returns False. Hint: use try and except statements to detect whether the user types in a noninteger string. Normally, the int() function will raise a ValueError if it is passed a noninteger string, as in int('puppy').

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT