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:

Note: The example output provided above is simply an example. You do not need to format your output to look exactly like mine. You simply need to ensure that you have met the technical requirements for this application and ensure your output is neat and professional looking.

i need help on this assignment please . this will be on python.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python Code:

def check_divisibility(num):
    # using the moculo operator to check divisibility
        if num%3==0 and num%5==0: 
                return 'Both'
        elif num%3==0:
                return '3'
        elif num%5==0:
                return '5'
        else:
                return ''


def main():
    # taking input from user 
        start_num = int(input('Give the start value: '))
        end_num = int(input('Give the end value: '))

    # displaying the beginning of the output
        print('Output:')
        print('------------------------------')
        
    # iterating over the values
        for i in range(start_num,end_num+1):
                var = check_divisibility(i)
                if var=='': # not divisible by either 3 or 5
                        print(str(i))
                else:
                        print(str(i)+'-'+var)

if __name__ == '__main__':
    main()                 

Screenshot of the Code:

1 8 9 11 2- def check_divisibility(num): 3 # using the moculo operator to check divisibility 4- if num%3==0 and num%5==0: 5 r

Output:

Give the start value: 1
Give the end value: 15
Output:
------------------------------
1
2
3-3
4
5-5
6-3
7
8
9-3
10-5
11
12-3
13
14
15-Both
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...

  • Python! True or false? When testing if two values are equal, we use the = operator....

    Python! True or false? When testing if two values are equal, we use the = operator. For example: if guess = 42: print("You guessed correctly!")

  • please code in python 1. Write a program to request the user enter a desired number...

    please code in python 1. Write a program to request the user enter a desired number of values. Create a loop to load the desired number of user-specified values into a list. Create two lists with the same values but generated in different ways. On list will be originally initialized to have the desired length before entering the loop. The other list will begin empty and values be appended for every iteration of the loop. Output from the program should...

  • Please solve it by Python 3 Write a program that asks the user for a positive...

    Please solve it by Python 3 Write a program that asks the user for a positive integer limit and prints a table to visualize all factors of each integer ranging from 1 to limit. A factor i of a number n is an integer which divides n evenly (i.e. without remainder). For example, 4 and 5 are factors of 20, but 6 is not. Each row represents an integer between 1 and 20. The first row represents the number 1,...

  • Part 1: Using Idle Write a Python Script that Does the Following 1. At the top...

    Part 1: Using Idle Write a Python Script that Does the Following 1. At the top of your program, import the math library as in from math import * to make the functions in the math module available. Create a variable and assign into it a constant positive integer number of your choice. The number should be at most 10. 1 Suppose we call this variable x for this writeup document Try something like x = 4 2. Create another...

  • Write a program that approximates the sum of this geometric series using a user- specified number...

    Write a program that approximates the sum of this geometric series using a user- specified number of terms. For example, if you named your program approx, calling approx(3) should use the first 3 terms of the series to calculate the approximation: Approximate result = 1/2 + 1/4 + 1/8 = 0.875... Note: the values are all powers of 1⁄2: (1/2)1, (1/2)2, (1/2)3, ... Next, have your program calculate the difference (rounded to 3 decimal places) between the value “1” and...

  • Divisibility by 9 To determine if a number is evenly divisible by 9, simply add all...

    Divisibility by 9 To determine if a number is evenly divisible by 9, simply add all of the digits in that number. If the sum is divisible by 9, then the original number also is divisible by 9. For example, notice that all of the multiples of 9 from 1 through 12 (9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, and 108) contain digits which sum to 9 or 18 in every case. In another example, to...

  • For this assignment, you will write a program that guesses a number chosen by your user....

    For this assignment, you will write a program that guesses a number chosen by your user. Your program will prompt the user to pick a number from 1 to 10. The program asks the user yes or no questions, and the guesses the user’s number. When the program starts up, it outputs a prompt asking the user to guess a number from 1 to 10. It then proceeds to ask a series of questions requiring a yes or no answer....

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