Question

Write a program in python using lists or tuples that asks for two positive integers n1...

Write a program in python using lists or tuples that asks for two positive integers n1 and n2 and prints out all the numbers that are divisible by 7 but are not a multiple of 5 within the range [n1,n2] (both included). The numbers obtained should be printed in a comma-separated sequence on a single line.

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

Ans:-

Code:-

def dispMul(n1,n2):
    t=[] #create an empty list
    for i in range(n1,n2+1): #iterate from range n1 to n2(both included)
        if i%7==0 and i%5!=0: #check if the number is divisible by 7 and not divisible by  5
            t.append(i) #if yes then append it into the list
    
    #print all the numbers in a single seperated by single comma
    print("All the numbers that are divisible by 7 but are not the multiples of 5:",end=" ")
    for i in t:
        if i!=t[-1]: #if not the last element then please add a comma after it
            print(i,end=", ")
        else:        #else only print the last element
            print(i)
#input values of n1 and n2 from user
n1=int(input("Enter the value of first number:"))
n2=int(input("Enter the value of second number:"))
dispMul(n1,n2) #call dispMul method to display all divisible of 7 but not divisible by 5

Output:-

Enter the value of first number: 7 Enter the value of second number: 50 All the numbers that are divisible by 7 but are not t

Add a comment
Know the answer?
Add Answer to:
Write a program in python using lists or tuples that asks for two positive integers n1...
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
  • Question 1: Write a python program that finds all numbers divisible by 7 but not multiple...

    Question 1: Write a python program that finds all numbers divisible by 7 but not multiple of 5. The range of number for searching is between 2000 and 3200 (both included). Output should be printed in a comma-separated sequence on a single line .

  • In Python 5. Write a function named listComprehensionDivisors that has 3 integer inputs, N, n1, and...

    In Python 5. Write a function named listComprehensionDivisors that has 3 integer inputs, N, n1, and n2. Using a single list comprehension to make a list of all of the numbers in the range 1..N that are either divisible by n1 or n2, where n1 and n2 can be any positive integers. After creating the list, your code should print out the following 2 lines: “We are printing all numbers from 1 to that are divisible by or ” “These...

  • Please use Python to solve this problem: Write a loop that reads positive integers from standard...

    Please use Python to solve this problem: Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates, it prints out, on a single line and separated by a single space, the sum of all the even integers read and the sum of all the odd integers read.

  • Write a program that prompts the user for two integers and then prints The sum The...

    Write a program that prompts the user for two integers and then prints The sum The difference The product The average The distance (absolute value of the difference) The maximum (the larger of the two) The minimum (the smaller of the two) hint: python defines max and min functions that accept a sequence of values, each separated with a comma. **program must be written in Python**

  • In Python, write a program that asks the user for a positive integer number. If the...

    In Python, write a program that asks the user for a positive integer number. If the user enters anything else, the program would ask the user to re-enter a number or enter -1 to quit. If it is a positive number, the program then prints out a multiplication table that goes up to that number. For example, if the user enters 10, the output would look something like this. https://www.vectorstock.com/royalty-free-vector/multiplication-table-on-white-background-vector-2721686

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : Alex got a sequence of n integers a1,a2,…,an as a birthday present. Alex doesn't like negative numbers, so he decided to erase the minus signs from all negative numbers. As a result, he got a sequence of non-negative numbers. Print the resulting sequence. For example, if the sequence is  1, 5, -3, 4,...

  • 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...

  • 1. Write a program that asks the user to enter two integers, obtains the numbers from...

    1. Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words “is larger.” If the numbers are equal, print the message “These numbers are equal.” Use only the single-selection form of the if statement you learned in this chapter.

  • please write in python Write a program that asks for beginning and ending number. The program...

    please write in python Write a program that asks for beginning and ending number. The program generates a set of 20 random numbers between the numbers and displays a count of each number generated. Sample output Enter starting and ending number separated by comma: 5, 25 5 occurs 2 times 7 occurs 1 time 8 occurs 1 time 10 occurs 2 times 12 occurs 1 time 13 occurs 2 time 15 occurs 5 times 16 occurs 1 time 20 occurs...

  • Write a program using M.I.P.S that asks user “how many positive number that is devisable by...

    Write a program using M.I.P.S that asks user “how many positive number that is devisable by 6 you want to add?” .Then your loopcounter would be the user input. If the user enters a positive number between 1 and 100 that is devisable by 6, you increment your loop counter and add it to the sum.. You need to decide if the positive number entered by the user is divisible by 6 or not. Your program should print an error...

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