Python Code Debug Questions
Python Code Debug Questions
Instructions:
1. Debug following programs and obtain exact output as given, but should not loose
meaning of the program.
2. You may either delete a line/add a new line/correct syntax error/correct logical
error/correct any other errors
3. Corrected programs upload in Edhitch in a file [ name the file with group number. ]
4. Winners will be selected based on speed , maximum number of correct answers and
accuracy
5. Upload maximum number of answers before 11 AM
6. If you solved all the programs before 11 AM upload immediately. Speed has points!!
7. Tip:- Solve simple one first
Program 1:
l=input('enter values').split(" ")
a=input('enter value to be searched')
for i in range(0,len(l)):
if a is l[i]:
pass
print(“Position:”)
print(i)
print('count is: ',l.count(a))
Exact Output:
enter values2 4 3 2 7 2
enter value to be searched2
Position: 0
Position: 3
Position: 5
count is: 3
Program 2
i=1
s=0
while i==10:
s=s+1
i=i+1
avg=s/10
print("the sum of first 10 numbers is",s)
print("the average of first 10 numbers is", avg)
Exact Output:
the sum of first 10 numbers is 10
the average of first 10 numbers is 1
Program 3
def count_ch(s,c):
count=0
for i in s:
if i ==c:
count+=1
return count
string=input("\n Enter a string ")
c=int(input("\n Enter character to search "))
count=count_ch(string,c)
print("In",string,c,"occurs ",count,"times")
Exact output
Enter a string lovely flowers
Enter character to search o
In lovely flowers o occurs 2 times
Program 4
def check_relation(a,b):
if a==b:
return 0
if a>b:
return 1
if a<b:
return -1
check_relation(3,5)
if res=='0':
print("a is equal to b")
if res=='1':
print("a is greater than b")
if res=='-1':
print("a is less than b")
Exact output
a is less than b
Program 5
for i in range(1,6):
print(i,end="")
for j in range(1,6):
print(j,end="")
print()
Exact output
12345
12345
12345
12345
12345
Program 6
# don’t add new line or don’t delete any line in this program
for i in range(1,10):
print(i,end="")
Exact output
13579
Program 7
string="python is easy"
yes=” “
print(yes+string[:-1])
Exact output
yes python is easy
Program 8
# Don’t remove any ‘+’ symbol from this program
a=float(input("enter any floating point value"))
print("The integer value of "+a+"="+int(a))
Exact output
enter any floating point value4.3
The integer value of 4.3=4
Program 9
max1=0
max2=0
n=int(input("Enter the number of element in the list"))
l=[]
for i in range(0,n):
L.append(int(input("Enter the number")))
for i in range(0,len(L)):
if L[i]>max1:
max1=max2
max1=L[i]
elif L[i]>max2 and L[i]<max1:
max1=L[i]
print("First max",max1)
print("Second max",max2)
Exact output
Program 10:
for i in range(n,0,-1):
for j in range(i,n):
print(" ",end="")
for j in range(1,((i*2)-1)):
print("*",end="")
print("\n")
Exact output
Enter value of n: 10
***** *****
******* *******
********* *********
*******************
*****************
***************
*************
***********
*********
*******
*****
***