Question

In: Computer Science

Python program please no def, main, functions Given a list of negative integers, write a Python...

Python program

please no def, main, functions

Given a list of negative integers, write a Python program to display each integer in the list that is evenly divisible by either 5 or 7. Also, print how many of those integers were found.

Sample input/output:

Enter a negative integer (0 or positive to end): 5
Number of integers evenly divisible by either 5 or 7: 0

Sample input/output:

Enter a negative integer (0 or positive to end): -5
-5 is evenly divisible by either 5 or 7.
Enter a negative integer (0 or positive to end): -35
-35 is evenly divisible by either 5 or 7.
Enter a negative integer (0 or positive to end): -3
Enter a negative integer (0 or positive to end): -7
-7 is evenly divisible by either 5 or 7.
Enter a negative integer (0 or positive to end): 0
Number of integers evenly divisible by either 5 or 7: 3

Solutions

Expert Solution

Code:

a=-1
lis=[]
i=0
c=0
while(1):
    a=int(input("Enter a negative integer(0 or positive to end):"))
    if(a>=0):
        break
    lis.append(a)
    if(lis[i]%5==0):
        print(lis[i],"is evenly divisble by either 5 or 7")
        c=c+1
    elif(lis[i]%7==0):
        print(lis[i],"is evenly divisble by either 5 or 7")
        c=c+1
    i=i+1
print("Number of integers evenly divisble by either 5 or 7:",c)  
   

Snippet code:

Output1:

Output2:


Related Solutions

Given a list of negative integers, write a Python program to display each integer in the...
Given a list of negative integers, write a Python program to display each integer in the list that is evenly divisible by either 5 or 7. Also, print how many of those integers were found. Sample input/output: Enter a negative integer (0 or positive to end): 5 Number of integers evenly divisible by either 5 or 7: 0 Sample input/output: Enter a negative integer (0 or positive to end): -5 -5 is evenly divisible by either 5 or 7. Enter...
In python write a program that gets a list of integers from input, and outputs non-negative...
In python write a program that gets a list of integers from input, and outputs non-negative integers in ascending order (lowest to highest). Ex: If the input is: 10 -7 4 39 -6 12 2 the output is: 2 4 10 12 39 For coding simplicity, follow every output value by a space. Do not end with newline
#Write a program in Python that given a list of positive integers, return another list where...
#Write a program in Python that given a list of positive integers, return another list where each element corresponds to the sum of the digits of the elements o#f the given list. #Example: # input # alist=[124, 5, 914, 21, 3421] # output # sum=[7, 5, 14, 3, 18]
Write an IPO diagram and Python program that has two functions, main and determine_grade. main –...
Write an IPO diagram and Python program that has two functions, main and determine_grade. main – Should accept input of five numeric grades from the user USING A LOOP.   It should then calculate the average numeric grade.    The numeric average should be passed to the determine_grade function. determine_grade – should display the letter grade to the user based on the numeric average:        Greater than 90: A 80-89:                 B 70-79:                 C 60-69:              D Below 60:           F Modularity:...
In python write a program that first creates a list with the integers 0 through 9...
In python write a program that first creates a list with the integers 0 through 9 and then traverses that list RECURSIVELY (no for/while loops allowed) and prints out the integers on the list. NOTE: creating the list does not have to be done recursively.
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
Language Python with functions and one main function Write a program that converts a color image...
Language Python with functions and one main function Write a program that converts a color image to grayscale. The user supplies the name of a file containing a GIF or PPM image, and the program loads the image and displays the file. At the click of the mouse, the program converts the image to grayscale. The user is then prompted for a file name to store the grayscale image in.
Please write code in C, thank you. Write a program that reads a list of integers,...
Please write code in C, thank you. Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: all even Ex: If the input is: 5 1 3 5 7 9...
1. Write a python program to create a list of integers using random function. Use map...
1. Write a python program to create a list of integers using random function. Use map function to process the list on the expression: 3x2+4x+5 and store the mapped elements in another list. Now use filter to do sum of all the elements in another list. 2. Write a function that takes n as input and creates a list of n lists such that ith list contains first 10 multiples of i. 3. Write a function that takes a number...
Write a python program to create a list of integers using random function. Use map function...
Write a python program to create a list of integers using random function. Use map function to process the list on the series: x + x2/2! + x3/3! + ….n and store the mapped elements in another list. Assume the value of n as 10
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT