'Hello need another expert's advice on how to program this exercise using Python 3. (see image). There's still an error on the test case of my code in Python. (see another image

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

'Hello need another expert's advice on how to program this exercise using Python 3. (see image). There's still an error on the test case of my code in Python. (see another image)

1 while(True):
nl=int(input("Enter nl: "));
n2=int (input("Enter n2: "));
if(nl>0 and n2>0 and n1<n2):
break;
print("Invalid input.");
2
3
4
6
7
8 countl=0
9 count2=0
10 count3=0
11 for n in range (nl, n2):
if(n%7==0 and n%3!=0):
12
13
countl += 1
14 for n in range (nl,n2):
if(n%5==0):
15
16
count2 += 1
17 for n in range (nl,n2):
18
if(n%5==0 and n%9==0):
19
count3 += 1
20 print("Number of integers that satisfy A from "+str(n1)+" to "+str(n2)+": "+str(count1));
21 print("Number of integers that satisfy B from "+str(n1)+" to "+str(n2)+": "+str(count2));
22 print("Number of integers that satisfy C from "+str(n1)+" to "+str(n2)+": "+str(count3));
Transcribed Image Text:1 while(True): nl=int(input("Enter nl: ")); n2=int (input("Enter n2: ")); if(nl>0 and n2>0 and n1<n2): break; print("Invalid input."); 2 3 4 6 7 8 countl=0 9 count2=0 10 count3=0 11 for n in range (nl, n2): if(n%7==0 and n%3!=0): 12 13 countl += 1 14 for n in range (nl,n2): if(n%5==0): 15 16 count2 += 1 17 for n in range (nl,n2): 18 if(n%5==0 and n%9==0): 19 count3 += 1 20 print("Number of integers that satisfy A from "+str(n1)+" to "+str(n2)+": "+str(count1)); 21 print("Number of integers that satisfy B from "+str(n1)+" to "+str(n2)+": "+str(count2)); 22 print("Number of integers that satisfy C from "+str(n1)+" to "+str(n2)+": "+str(count3));
Ask for two user inputs n1 and n2. Keep asking for inputs until the conditions below are satisfied.
Both n1 and n2 must be positive integers. n1 should be less than n2.
Then print the following:
Condition 1: Count all numbers between n1 and n2 that are divisible by 7 and not divisible by 3
Condition 2: Count all numbers between n1 and n2 that are divisible by 5
Condition 3: Count all numbers between n1 and n2 that are divisible by 5 and divisible by 9
Sample Input #2
Sample Input #1
3
1
46
1
1
Sample Output #1
Enter nl: Enter n2: Number of integers that satisfy A from 3 to 46: 4
Number of integers that satisfy B from 3 to 46: 9
Number of integers that satisfy C from 3 to 46: 1
Sample Output #2
Enter nl: Enter n2: Invalid input.
Enter nl: Enter n2: Invalid input.
Enter nl: Enter n2: Number of integers that satisfy A from 1 to 2: 0
Number of integers that satisfy B from 1 to 2: 0
Number of integers that satisfy C from 1 to 2: 0
Transcribed Image Text:Ask for two user inputs n1 and n2. Keep asking for inputs until the conditions below are satisfied. Both n1 and n2 must be positive integers. n1 should be less than n2. Then print the following: Condition 1: Count all numbers between n1 and n2 that are divisible by 7 and not divisible by 3 Condition 2: Count all numbers between n1 and n2 that are divisible by 5 Condition 3: Count all numbers between n1 and n2 that are divisible by 5 and divisible by 9 Sample Input #2 Sample Input #1 3 1 46 1 1 Sample Output #1 Enter nl: Enter n2: Number of integers that satisfy A from 3 to 46: 4 Number of integers that satisfy B from 3 to 46: 9 Number of integers that satisfy C from 3 to 46: 1 Sample Output #2 Enter nl: Enter n2: Invalid input. Enter nl: Enter n2: Invalid input. Enter nl: Enter n2: Number of integers that satisfy A from 1 to 2: 0 Number of integers that satisfy B from 1 to 2: 0 Number of integers that satisfy C from 1 to 2: 0
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education