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"...

  • 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...

  • 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

  •    PYTHON --create a function that accepts a list of numbers and an int that returns...

       PYTHON --create a function that accepts a list of numbers and an int that returns index of 2nd occurrence of the int in list, otherwise returns None if # does not repeat more 2 or more times EX: [10,24,3,45,10,49,4,5], 10) returns 4 --create a function that accepts a string that returns true if every letter of the alphabet can be found at least one time in the string, (has to be the lowercase alphabet), and false otherwise.    for...

  • PYTHON The function longest that returns the longest of two strings. The function count_over that takes...

    PYTHON The function longest that returns the longest of two strings. The function count_over that takes a list of numbers and an integer nand returns the count of the numbers that are over n. The function bmi that takes two parameters height and weight and returns the value of the body mass index: a person's weight in kg divided by the square of their height in meters. def longest(string1, string2): """Return the longest string from the two arguments, if the...

  • Create a function called countWords(string): That will count words in given string by user. Use Python...

    Create a function called countWords(string): That will count words in given string by user. Use Python 3.6 If user inputs "Mary had a little lamb" it should return 5

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
ADVERTISEMENT