Question

In this assignment we are asking the user to enter two number values, the starting and...

In this assignment we are asking the user to enter two number values, the starting and ending numbers for our application. Having these values, we then construct a loop that will increment by one (1) from the starting number through (and including) the ending number. Within this loop we will check the current value of our number to see if it is evenly divisible by 3, then by 5, and then by both 3 and 5. We will output all values to the screen and note which are divisible by "3", "5", or "Both."

Important: As part of this assignment the checking to see if a value/number is evenly divisible by 3, by 5, or by both is to be handled within a function or set of functions. How you implement this is up to you. But your project needs to implement at least one function.

For example, if the user enters 1 for the starting number and 100 for the ending, we will loop through all values of 1 through 100, one at a time. For the first value we will print "1". For the next "2". But for three we will print "3 - 3". For five "5 - 5". But for 15 we will print "15 - Both".

This should not be difficult work. They key to this is understand for each value whether it is evenly divisible by 3 or 5 or by both 3 and 5. This requires that you use the Modulo operator in Python. All programming languages have a modulo operator.

When complete, your output should be as pictured below:

In this example, my starting value is 1 and the ending value is 25:

In this example, my starting value is 15 and the ending value is 30:

  • You must have a set of comments at the top of the program that identifies the programmer, date, and name of the program file. Furthermore, you must provide a description of what this program is and what it does. Each of these comments must be on individual lines.
  • The following two pieces of data will be entered by the user: starting number and ending number
  • Using the entered data, you will loop through this range of values one at a time.
  • For each value in your range you will determine if it is evenly divisible by 3, by 5, or by both 3 and 5.
  • The value—in all cases—will be output to the screen. But if it is evenly divisible by 3, 5, or both you will note that in the output.
  • You must demonstrate your knowledge of functions by creating at least one function: to perform the check for whether the current value is evenly divisible by 3, 5, or both. You can create as many functions as you wish, but you must have at least one function.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
def divisible_by_3(num):
    if num % 3 == 0:  # If divisible by 3 return true or false
        return True
    else:
        return False

def divisible_by_5(num):
    if num % 5 == 0:  # If divisible by 3 return true or false
        return True
    else:
        return False


if __name__ == '__main__':
    # Ask user to enter starting and ending point
    starting_value = int(input('Enter starting value: '))
    ending_value = int(input('Enter ending value: '))
    # Create a loop from starting point to ending point
    # If divisible by 3 and 5, print i - Both
    # Else if divisible by 3, print i - 3
    # Else if divisible by 5, print i - 5
    # Else, print the number
    for i in range(starting_value, ending_value + 1):
        if divisible_by_3(i) and divisible_by_5(i):
            print(i, '- Both')
        elif divisible_by_3(i):
            print(i, '- 3')
        elif divisible_by_5(i):
            print(i, '- 5')
        else:
            print(i)

SCREENSHOT

1 2 3 def divisible_by_3 (num): if num & 3 == 0: # If divisible by 3 return true or false return True else: return false 4 5

OUTPUT
E:\Practice\Python\venv\Script Enter starting value: 1 Enter ending value: 25 1 2 3 3 4 Сл 5 6 - 3 7 8 Сл 9 - 3 10 11 12 13 -

Add a comment
Know the answer?
Add Answer to:
In this assignment we are asking the user to enter two number values, the starting and...
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
  • In this assignment we are asking the user to enter two number values, the starting and...

    In this assignment we are asking the user to enter two number values, the starting and ending numbers for our application. Having these values, we then construct a loop that will increment by one (1) from the starting number through (and including) the ending number. Within this loop we will check the current value of our number to see if it is evenly divisible by 3, then by 5, and then by both 3 and 5. We will output all...

  • need help with python program The objectives of this lab assignment are as follows: . Input...

    need help with python program The objectives of this lab assignment are as follows: . Input data from user Perform several different calculations Implement conditional logic in loop • Implement logic in functions Output information to user Skills Required To properly complete this assignment, you will need to apply the following skills: . Read string input from the console and convert input to required numeric data-types Understand how to use the Python Modulo Operator Understand the if / elif /...

  • MULIMI Umplicated than the hrst assignment. Write a program that will let the user enter an...

    MULIMI Umplicated than the hrst assignment. Write a program that will let the user enter an integer. If the integer is less than 5 make the actual input value be 50. We will call the value that the user put in N. Print the integers from 1 to None number on each line. If the number you are going to print is divisible by 3 print the word fuzz instead of the number. If the number is divisible by 5...

  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

  • Write a program that prompts the user to enter an integer and checks whether the number...

    Write a program that prompts the user to enter an integer and checks whether the number is divisible by both 5 and 6, divisible by 5 or 6, or just one of them (but not both). SAMPLE OUTPUT Enter an integer: 10 Is 10 divisible by 5 and 6? False Is 10 divisible by 5 or 6? True Is 10 divisible by 5 or 6, but not both? True (Python programming language)

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

  • in Python: Write a program that allows the user to enter a number between 1-5 and...

    in Python: Write a program that allows the user to enter a number between 1-5 and returns an animal fact based on what the user entered. The program should 1. Continue to run until the user enters “quit” to terminate the program, and 2. Validate the user’s input (the only acceptable input is 1, 2, 3, 4, 5 or “quit”). You can use the following animal facts: An octopus is a highly intelligent invertebrate and a master of disguise. Elephants...

  • MUST BE WRITTEN IN C++ All user input values will be entered by the user from...

    MUST BE WRITTEN IN C++ All user input values will be entered by the user from prompts in the main program. YOU MAY NOT USE GLOBAL VARIABLES in place of sending and returning data to and from the functions. Create a main program to call these 3 functions (5) first function will be a void function it will called from main and will display your name and the assignment, declare constants and use them inside the function; no variables will...

  • C++ Write a program that prompts the user to enter two positive integers: num1 and num2....

    C++ Write a program that prompts the user to enter two positive integers: num1 and num2. - Validate that num1 is less than num2 and that both numbers are positive. If any of these conditions are not met, allow the user to re-enter num1 and num2 until the input is determined valid. - For all integers from num1 through num2, print the word keyboard if the current integer is divisible by 2 and print the word mouse if the current...

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
Active Questions
ADVERTISEMENT