Question: THREE QUESTIONS - USE PYTHON LANGUAGE 2. Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input

THREE QUESTIONS - USE PYTHON LANGUAGE

2. Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input.

For example:

Test Input Result
print(yesOrNo()) hello blank no False

3. Use the Design Recipe to write a function called runningTotal that repeatedly asks the user to input integers at the keyboard until they type the word done. Print the sum of the values they entered. You may assume the user will only enter integers or "done".

For example:

Test Input Result
runningTotal() 3 5 done 8

4. Assume that you have a function called is_prime which consumes a positive number and returns True if the number is prime and False if the number is not prime.

Your task is to now to use the Design Recipe to write a main function, which prompts the user for a positive integer n and prints the first nprimes to the console, and takes no parameters.

If the user input 3, your program should display:

2

3

5

For example:

Test Input Result
def is_prime(n): """ determines if the input is a prime number or not """ if n < 0: print("positive numbers only!") return for i in range(2,n): if n % i == 0: return False return n != 1 main() 3 2 3 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!