Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In a new file called LabE1.py, implement a Python user defined function called ftsecTokhr that converts speed given in units of feet per second to

In a new file called LabE1.py,

implement a Python user defined function called ftsecTokhr that converts speed given in units of feet per second to speed in units of kilometers per hour. Complete the following:

Determine the formula for converting ft/sec into km/hr. Search the internet if you are not sure.

Write the user defined function ftsecTokhr to convert feet/second into km/hr. Remember, your single input parameter is feet per second, and your single output parameter is kilometers per hour. Assume the input and output is a floating point type.

After the definition of the function, add code in LabE1.py to test the function by getting a value in feet per second from the user, calling the function, and then displaying the kilometers per hour result. Assume the user puts in a valid floating point number (hint: dont forget to print appropriate units!).

How many feet per second? 10

10.9728 kilometers per hour

How many feet per second? 194.244

213.14 kilometers per hour

Prime Numbers

In a new file called LabE2.py Implement a user defined function called is_prime which accepts one input parameter (an integer number) and returns a Boolean value as follows:

-True if the input parameter is a prime number

-False if the input parameter is NOT a prime number

Note: The following is the full blown algorithm (or pseudo code) which does not work in Python, but gives a workable structure for the function. Your job is to convert this algorithm into the Python function as described above:

Function is_prime(Input number) Returns a boolean flag

-If the input number is less than or equal to zero, then:

-set flag to false

-Else, If the input number is one, then:

-set flag to true

-Other wise:

Set divisor equal to 2.

Determine the remainder of the input number divided by the divisor.

While the remainder of the input number divided by the divisor is not equal to 0:

-Add one to the divisor.

- Determine the remainder of the input number divided by the divisor.

End while loop

If the input number is equal to the divisor, then set flag to true

Otherwise set the flag to false

-End the if/else/otherwise code

In the LabE2.py file, AFTER your definition of the is_prime function, ask the user for a positive integer and, using the is_prime function, print out if the number is prime or not. If the user does not input a positive integer correctly, have them re-try (as many times as needed)

E.g.:

Enter a positive integer: 6

6 is not a prime number

Enter a positive integer: -3

That is not a positive integer, try again: 3.1

That is not a positive integer, try again: 3

3 is a prime number

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions