60% found this document useful (5 votes)
10K views

Python Code Debug Questions

The document provides instructions for debugging Python programs and submitting correct solutions. Students are asked to debug 10 programs by correcting errors without changing the overall meaning. They should submit their corrected programs in a file before 11 AM for a chance to win prizes based on speed, number of correct solutions, and accuracy. Simple programs should be solved first. The document provides the exact expected output for each of the 10 programs to debug.

Uploaded by

joby
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
60% found this document useful (5 votes)
10K views

Python Code Debug Questions

The document provides instructions for debugging Python programs and submitting correct solutions. Students are asked to debug 10 programs by correcting errors without changing the overall meaning. They should submit their corrected programs in a file before 11 AM for a chance to win prizes based on speed, number of correct solutions, and accuracy. Simple programs should be solved first. The document provides the exact expected output for each of the 10 programs to debug.

Uploaded by

joby
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Python code Debugging- 12/10/2019

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

Enter the number of element in the list10


Enter the number10
Enter the number90
Enter the number90
Enter the number90
Enter the number90
Enter the number90
Enter the number90
Enter the number80
Enter the number70
Enter the number60
First max 90
Second max 80

Program 10:

n=int(input("Enter value of n : "))


for i in range(n//2,n+1,2):
for j in range(1,n-i,2):
print(" ",end="")
for j in range(1,i+1) :
print("*")
for j in range(1,n-i):
print(" ",end="")
for j in range(1,i):
print("*",end="")
print("\n")

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
***** *****

******* *******

********* *********

*******************

*****************

***************

*************

***********

*********

*******

*****

***

You might also like