Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 9th International Conference Dasfaa 2004 Jeju Island Korea March 2004 Proceedings Lncs 2973

Authors: YoonJoon Lee ,Jianzhong Li ,Kyu-Young Whang

2004th Edition

3540210474, 978-3540210474

More Books

Students also viewed these Databases questions