'''The expected input and output are given (see right side) but my output and my code (on the left) did not match, what seems to be the problem? Thank you

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

'''The expected input and output are given (see right side) but my output and my code (on the left) did not match, what seems to be the problem? Thank you!

1 while(True):
b=int(input("Enter b: "));
a=int(input("Enter a: "));
#infinite loop
#input b
#input a
Your code did not pass this test case.
4
Input
if(b>0 and a>0 and b>a and (b-a)%2==0): #if valid input
break;
print("Invalid input");
#for upper part
5
6
#exit from loop
7
#if Invalid input print and continue in loop
8
4
9 vfor n in range (0, (b-a)//2):
2
10
#for spaces
Your Output
for spaces in range (0,b-n):
print (" ",end="");
11
12
Enter b: Enter a: Invalid input
13
#for stars
Enter b: Enter a:
for star in range (0,2*n+1):
print ("*",end="");
print();
#for middle part
14
*a*
15
*aaa*
16
17
18 level=1;
19 vfor n in range ( (b-a)//2,b-a+1):
Expected Output
Enter b: Enter a: Invalid input.
20
#for spaces
Enter b: Enter a:
for spaces in range (0,b-n):
print (" ",end="");
#for stars
for star in range (0, (b-a)//2):
21
22
*a*
23
*aaa*
24
*******
25
print("*",end="");
#for characters
26
for char in range (0,2*level-1):
print ("a", end="");
level+=1;
#for ending stars
for star in range (0, (b-a)//2):
print ("*",end="");
print();
#for lower part
27
28
29
30
31
32
33
34
35 for n in range (b-a+1,b):
#for spaces
for spaces in range (0,b-n):
print (" ",end="");
36
37
38
39
#for stars
for star in range (0,2*n+1):
print ("*",end="");
print();
40
41
42
Transcribed Image Text:1 while(True): b=int(input("Enter b: ")); a=int(input("Enter a: ")); #infinite loop #input b #input a Your code did not pass this test case. 4 Input if(b>0 and a>0 and b>a and (b-a)%2==0): #if valid input break; print("Invalid input"); #for upper part 5 6 #exit from loop 7 #if Invalid input print and continue in loop 8 4 9 vfor n in range (0, (b-a)//2): 2 10 #for spaces Your Output for spaces in range (0,b-n): print (" ",end=""); 11 12 Enter b: Enter a: Invalid input 13 #for stars Enter b: Enter a: for star in range (0,2*n+1): print ("*",end=""); print(); #for middle part 14 *a* 15 *aaa* 16 17 18 level=1; 19 vfor n in range ( (b-a)//2,b-a+1): Expected Output Enter b: Enter a: Invalid input. 20 #for spaces Enter b: Enter a: for spaces in range (0,b-n): print (" ",end=""); #for stars for star in range (0, (b-a)//2): 21 22 *a* 23 *aaa* 24 ******* 25 print("*",end=""); #for characters 26 for char in range (0,2*level-1): print ("a", end=""); level+=1; #for ending stars for star in range (0, (b-a)//2): print ("*",end=""); print(); #for lower part 27 28 29 30 31 32 33 34 35 for n in range (b-a+1,b): #for spaces for spaces in range (0,b-n): print (" ",end=""); 36 37 38 39 #for stars for star in range (0,2*n+1): print ("*",end=""); print(); 40 41 42
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY