Question

In: Computer Science

Solve the following question by using python language In range of 1-10000 if the numbers are...

Solve the following question by using python language

In range of 1-10000 if the numbers are divisible by n1 increase count by 1 , if the number is divisible by n2 increase count by 2, and if the number are divisible by n3 increase the count by 3

if none of the above conditions match for the number, increase count by the number.

n1=10 +17

n2=50 +21

n3=100 +9

Solutions

Expert Solution

Here is the answer for your question in Python Programming Language.

Kindly upvote if you find the answer helpful.

NOTE : I have taken simple if statements instead of if else because if one number is divide by all n1,n2,n3 or by any two of n1,n2 and n3 then using if else will increment count for only one condition.

####################################################################

CODE :

n1 = 10 + 17
n2 = 50 + 21
n3 = 100 + 9
count = 0
for i in range(1,10000):
"""I have taken flag to check true if any of the conditions is satisfied"""
"""I have taken if one number can be divided by n1,n2,n3 then
using if else will satisfy only one condition"""
flag = 0
if i % n1 == 0:
flag = 1
count = count + 1
if i % n2 == 0:
flag = 1
count = count + 2
if i % n3 == 0:
flag = 1
count = count + 3

if flag == 0:
count = count + i
  
print(count)   

####################################################################

SCREENSHOTS :

Please see the screenshots of the code below for the indentations of the code. As python is a language of indentations kindly check the indentations of the code before execution.

############################################################################

OUTPUT :

Any doubts regarding this can be explained with pleasure :)


Related Solutions

Please solve this question in C++ language using recursion. Q (1) Write functions for each of...
Please solve this question in C++ language using recursion. Q (1) Write functions for each of the following problems. Each problem should be solved by writing a recursive function. Your final program should not have any loops in it. Write a function that uses recursion to raise a number to a power. The function should take two arguments, the number to be raised to the power (floating point) and the power (a non-negative int).                                                                                       (10 Points) Write a boolean...
1. Using domain and range transformations, solve the following recurrence relations: a) T(1) = 1, T(n)...
1. Using domain and range transformations, solve the following recurrence relations: a) T(1) = 1, T(n) = 2T(n/2) + 6n - 1 b) T(1) = 1, T(n) = 3T(n/2) + n^2 - n
a summary explaining the basic understanding of the following programming concepts using a language of python:...
a summary explaining the basic understanding of the following programming concepts using a language of python: •Variables •Arithmetic and Logical operations •Sequential coding (Structured programming •Decision structure (If statements) •Repetition structure •Functions with some coding demos inside visual studio code python IDE which can be sent as screenshot. preferably a typed summary please which can be written into powerpoint pleaseeeee ???
Using python as the coding language please write the code for the following problem. Write a...
Using python as the coding language please write the code for the following problem. Write a function called provenance that takes two string arguments and returns another string depending on the values of the arguments according to the table below. This function is based on the geologic practice of determining the distance of a sedimentary rock from the source of its component grains by grain size and smoothness. First Argument Value Second Argument Value Return Value "coarse" "rounded" "intermediate" "coarse"...
Write a program in python language, which accepts 2 numbers and a + sign (for addition)...
Write a program in python language, which accepts 2 numbers and a + sign (for addition) A sign - (for subtraction) A sign * (for multiplication), / (for division) Then calculate and to display the result of the operation he chose with the two numbers. Displaying the appropriate message
Question 5 (10 marks) Python Language What is the output of the following code ? (2...
Question 5 Python Language What is the output of the following code ? (2 points) a, b = 0, 1 while b < 10: print b a, b = b, a+b B. Explain List Comprehension (2 points) Given v = [1 3 5] w = [ [2*x, x**2] for x in v] What is the content of w? c. What is tuple ?   What is the difference between tuple and list ? (2 points) D. What is a module ?  ...
>>python Question: Create program which acquires an integer in the range 1-17, and then outputs a...
>>python Question: Create program which acquires an integer in the range 1-17, and then outputs a times table from that acquired figure. Function should print times table and another function which acquires and returns the ranged integer. Therefore they are distinct functions. Specific details to include: You can also in the central area of the code script allocate a value which is returned aside a function to a variable.(For example table=yourchoiceinteger(1,17).) Therefore that table which is the variable will be...
Solve please in python b) Create a program that shows a series of numbers that start...
Solve please in python b) Create a program that shows a series of numbers that start at a and increase from 5 to 5 until reaching b, where a and b are two numbers captured by the user and assumes that a is always less than b. Note that a and b are not necessarily multiples of 5, and that you must display all numbers that are less than or equal to b. c) Create a program that displays n...
(Please solve the question using C Language. Thanks). Write a function called is_perfect which takes an...
(Please solve the question using C Language. Thanks). Write a function called is_perfect which takes an integer n and returns 1 if n is a perfect number, otherwise it will return 0. If the sum of a number’s proper divisors are equal to the number, than the number is called a perfect number. For example, 6 is a perfect number: 6=1+2+3.
Please solve this problem with Python Language. P#2. A Pythagorean triplet is a set of three...
Please solve this problem with Python Language. P#2. A Pythagorean triplet is a set of three natural numbers, a < b < c, for which a2 + b2 = c2 . For example, 32 + 42 = 52. And a + b + c = 3 + 4 + 5 = 12. There exists exactly two Pythagorean triplet for which a + b + c = 300. Find a, b, c. Hints: Level-0 Algorithm: 1. Find the possible ranges of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT