Assignment 4 PIP
Assignment 4 PIP
Assignment 4 PIP
2. Consider the following Python code intended to print inverse right triangle for given numbers of rows
nRows. For example, for nRows = 5, the following inverted triangle should be printed:
*****
****
***
**
*
During testing, it was found that the program does not produce even the single line of output. Debug
the following script using the debugger.
Program to print inverse right triangle.
Step by Step Debugging:
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
========== RESTART: /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py =========
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py(3)<module>()
-> def invertedRightTriangle(nRows):
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py(7)<module>()
-> def main():
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py(11)<module>()
-> if __name__ == '__main__':
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py(12)<module>()
-> main()
(Pdb) s
--Call--
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py(7)main()
-> def main():
(Pdb) n
Enter number of rows: 5
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py(9)main()
-> invertedRightTriangle(nRows)
(Pdb) s
--Call--
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py(3)invertedRightTriangle()
-> def invertedRightTriangle(nRows):
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py(4)invertedRightTriangle()
-> for i in range(nRows, 0):
(Pdb) s
--Return--
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py(4)invertedRightTriangle()->None
-> for i in range(nRows, 0):
(Pdb) q
Traceback (most recent call last):
File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode
exec(code, self.locals)
File "/media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py", line 12, in <module>
main()
File "/media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py", line 9, in main
invertedRightTriangle(nRows)
File "/media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q2.py", line 4, in
invertedRightTriangle
for i in range(nRows, 0):
File "/usr/lib/python3.10/bdb.py", line 94, in trace_dispatch
return self.dispatch_return(frame, arg)
File "/usr/lib/python3.10/bdb.py", line 156, in dispatch_return
if self.quitting: raise BdbQuit
bdb.BdbQuit
3. Consider the Python script given below intended to compute the percentage. During testing, it was
found that percentage computed was not accurate rather rounded to lower bound integer value. Debug
the following script using the debugger.
Program to print inverse right triangle
Step by Step Debugging:
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
========== RESTART: /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py =========
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(3)<module>()
-> def main():
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(20)<module>()
-> if __name__ == '__main__':
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(21)<module>()
-> main()
(Pdb) s
--Call--
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(3)main()
-> def main():
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(4)main()
-> totalMarks = 0
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(5)main()
-> i = 0
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(6)main()
-> while True:
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(7)main()
-> marks = input("Enter marks for subject "+str(i+1)+":")
(Pdb) n
Enter marks for subject 1:75
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(8)main()
-> if marks=='':
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(10)main()
-> marks = int(marks)
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(11)main()
-> if marks<0 or marks>100:
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(14)main()
-> i += 1
(Pdb) s
> /media/vivek/Vivek/3rd Year/PIP/Assignment 4/Q3.py(15)main()
-> totalMarks += marks
(Pdb) s
4. Consider the Python given below intended to determine whether the given year is a leap year. During
testing, it was found that an year such as 1800 or 2100, despite being non-leap year, was also displayed
as a leap-year. Debug the following script using the debugger.
Program to print Leap Year
5. Consider the Python script given below intended to find HCF. During testing, it was found that program
yields an error for numbers having no common factor other than 1. Debug the following script
using the debugger.
Program to find HCF of two numbers
> /home/vivek/Documents/PIP/Q4.py(16)main()
-> num2 = int(input("Enter second number: "))
(Pdb) n
Enter second number: 13
> /home/vivek/Documents/PIP/Q4.py(17)main()
-> print(findHCF(num1,num2))
(Pdb) n
UnboundLocalError: local variable 'HCF' referenced before assignment
> /home/vivek/Documents/PIP/Q4.py(17)main()
-> print(findHCF(num1,num2))
(Pdb) q
Traceback (most recent call last):
File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode
exec(code, self.locals)
File "/home/vivek/Documents/PIP/Q4.py", line 20, in <module>
main()
File "/home/vivek/Documents/PIP/Q4.py", line 17, in main
print(findHCF(num1,num2))
File "/usr/lib/python3.10/bdb.py", line 96, in trace_dispatch
return self.dispatch_exception(frame, arg)
File "/usr/lib/python3.10/bdb.py", line 176, in dispatch_exception
if self.quitting: raise BdbQuit
bdb.BdbQuit