Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
26 views11 pages

ASSIGNMENT-3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 11

ERROR FINDING QUESTIONS

Q1. Find error in the following code(if any) and correct code by rewriting code and
underline the correction;‐
x= int(“Enter value of
x:”) for in range [0,10]:
if x=y
print( x +
y)
else:
print( x‐y)

Q2. Rewrite the following program after finding and correcting syntactical errors and
underlining it.
a, b = 0
if (a =
b) a +b
=c
print( z)

Q3. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
250 = Number
WHILE Number<=1000:
if Number=>750
print (Number)
Number=Number+100
else
print( Number*2)
Number=Number+50

Q4. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
Val = int(rawinput("Value:"))
Adder = 0
for C in range(1,Val,3)
Adder+=C
if C%2=0:
Print (C*10)
Else:
print (C*)
print (Adder)
Q5. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
25=Val
for I in the
range(0,Val) if I
%2==0:
print( I+1)
Else:
print (I‐1
Q6. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
STRING=""WELCOME
NOTE""
for S in range[0,8]:
print (STRING(S))

Q7. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
a=int{input("ENTER FIRST NUMBER")}
b=int(input("ENTER SECOND NUMBER"))
c=int(input("ENTER THIRD NUMBER"))
if a>b and a>c
print("A IS GREATER")
if b>a and b>c:
Print(" B IS GREATER")
if c>a and c>b:
print(C IS GREATER)

Q8. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
i==1
a=int(input("ENTER FIRST NUMBER"))
FOR i in range[1, 11];
print(a,"*=", i ,"=",a *
i)

Q9. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
a=”1”
while a>=10:
print("Value of a=",a)
a=+1

Q10. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.

Num=int(rawinput("Number:"))
sum=0
for i in range(10,Num,3)
Sum+=1
if i%2=0:
print(i*2)
Else:
print(i*3 print Sum)

Q11. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.

weather='raining'
if weather='sunny':
print("wear sunblock")
elif weather='snow':
print("going skiing")
else:
print(weather)
Q12. Write the modules that will be required to be imported to execute the following
code in Python.

def main( ):
for i in range (len(string))
): if string [i] = = ‘’ “
print
else:
c=string[i].upper()
print( “string is:”,c)
print (“String length=”,len(math.floor()))

Q13. Observe the following Python code very carefully and rewrite it after removing all
syntactical errors with each correction underlined.

DEF execmain():
x = input("Enter a number:")
if (abs(x)=x):
print ("You entered a positive number")
else:
x=*‐1
print "Number made positive:"x
execmain()

Q14. Rewrite the following code in python after removing all syntax error(s).Underline
each correction done in the code

x=integer(input('Enter 1 or 10'))
if x==1:
for x in range(1,11)
Print(x)
Else:
for x in range(10,0,‐1):
print(x)

Q15. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.

30=To
for K in range(0,To)
IF k%4==0:
print (K*4)
else
print (K+3)

OUTPUT FINDING QUESTIONS


Q1. Find output generated by the following code:
p=10
q=20
p*=q//3
q+=p=q**2
print(p, q)
Q2. Find output generated by the following code:
String Str=”Computer”
Str[‐4:]
Str*2

Q3. Find out the output of the Following –


x=20
x=x+5
x=x‐10
print (x)
x, y=x‐1,50
print (x, y)

Q4. Find out the output of the Following –


for a in range(3,10,3):
for b in range(1,a,2):
print(b, end=’
‘) print( )

Q5. FIND OUTPUT OF FOLLOWING


x=10
y=5
for i in range(x‐y*2):
print("%",i)

Q6. Find output generated by the following code:


x="one"
y="two"
c=0
while c<len(x):
print(x[c],y[c])
c=c+1

Q7. Find output generated by the following code:


for i in range(‐1,7,2):
for j in
range(3):
print(i,j)

Q8. Find output generated by the following code:


string=”aabbcc”
count=3
while True:
if string[0]=='a':
string=string[2:]
elif string[‐1]=='b':
string=string[:2]
else:
count+=1
break
print(string)
print(count)

Q9. Find output generated by the following code:


x="hello world"
print(x[:2],x[:‐2],x[‐2:])
print(x[6],x[2:4])
print(x[2:‐3],x[‐4:‐2])
Q10. Find and write the output of the following python code :
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print(Msg3)
Q11. Find and write the output of the following python code:
Text1="AISSCE 2018"
Text2=""
I=0
while I<len(Text1):
if Text1[I]>="0" and Text1[I]<="9":
Val = int(Text1[I])
Val = Val + 1
Text2=Text2 + str(Val)
elif Text1[I]>="A" and Text1[I] <="Z":
Text2=Text2 + (Text1[I+1])
else:
Text2=Text2 + "*"
I=I+1
print (Text2)

Q12. Find output generated by the following code:


line = "I'll come by
then." eline = ""
for i in line:
eline += chr(ord(i)+3)
print(eline)

Q13. Find output generated by the following code:


line = "What will have so
will" L = line.split('a')
for i in L:
print(i, end=' ')

Q14. Find output generated by the following code:


p=5/2
q=p*4
r=p+q
p+=p+q+r
q‐=p+q*r
print(p,q,r)

Q15. Find output generated by the following code:


a=(2 + 3) ** 3 – 6 / 2
b=(2 + 3) * 5// 4 + (4 + 6) / 2
c=12 + ( 3 * 4 – 6 ) / 3
d=12 % 5 * 3 + (2 * 6) // 4
print(a, b, c, d)
Q16. Find output generated by the following code:
line = "I'll come by
then." eline = ""
for i in line:
eline += chr(ord(i)+3)
print(eline)

Q17. Find output generated by the following code:


line = "What will have so
will" L = line.split('a')
for i in L:
print(i, end=' ')

Q18. Find output generated by the following code:


p=5/2
q=p*4
r=p+q
p+=p+q+r
q‐=p+q*r
print(p,q,r)

Q19. Find output generated by the following code:


a=(2 + 3) ** 3 – 6 / 2
b=(2 + 3) * 5// 4 + (4 + 6) / 2
c=12 + ( 3 * 4 – 6 ) / 3
d=12 % 5 * 3 + (2 * 6) // 4
print(a, b, c, d)
Q20. Find the output of the give program :
x=
"abcdef" i =
"a" while i
in x:
print(i, end = " ")

Q21. Find the output of the following numbers:


Num = 20
Sum = 0
for I in range (10, Num, 3)
Sum+=i
if i%2==0:
print i*2
else:
print i*3

Q22. Find the output of the following


Text=”gmail@com”
L=len(Text)
ntext=” “
for i in range (0,L):
if text[i].isupper():
ntext=ntext+text[i].lower()
elif text[i].isalpha():
ntext=ntext+text[i].upper()
else:
ntext=ntext+’bb’
Q.23 Which of the following is valid arithmetic operator in Python:
(i)// (ii)? (iii)< (iv)and

Q24. Write the type of tokens from the following:


(i) if (ii) roll_no

Q25. Which of the following are valid operators in Python:


(i) ** (ii) */ (iii) like (iv) ||
(v) is (vi) ^ (vii) between (viii) in

Q26.Which of the following can be used as valid variable identifier(s) in Python?


(i) 4thSum (ii) Total
(iii) Number# (iv) _Data

1 What will be the output of following code-


str="hello"
str[:2]
2 What will be the output of following code-
str='Hello'
res=''
for i in range(len(str)):
res=res+str[i]
print(res)
3 What will be the output of following code-
s='Hi!'
s1='Hello'
s2=s[:2]+s1[len(s1)-2:]
print(s2)
4 What will be the output of following code-
'ba'+'na'*2
5 What will be the output of following code-
s='Welcome to python4csip.com'
print(s.find('come'))
s.count('o')
6 What will be the output of following program:
s='Hello'
for i in s:
print(i,end='#')
7 What will be the output of following program:
for i in 'hardik':
print(i.upper())
8 What will be the output of following program:
s='Hello'
for i in s:
print('Welcome')
9 What will be the output of following program:
str='virat'
for i in str:
print(str.upper())
WORKSHEET – STRING HANDLING-XI
10 What will be the output of following program:
a='hello'
b='virat'
for i in range(len(a)):
print(a[i],b[i])
11 What will be the output of following program:
a='hello'
b='virat'
for i in range(len(a)):
print(a[i].upper(),b[i])
12 What will be the output of following program:
print("xyyzxyzxzxyy".count('xyy', 2, 11))
13 What will be the output of following program:
print(“hello”+1+2+3)
14 What will be the output of following program:
str1 = "PYTHON4CSIP.COM"
print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
15 What will be the output of following program: str =
"my name is kunfu pandya";
print (str.capitalize())
16 What will be the output of following program:
str1 = 'Hello'
str2 ='World!'
print('str1 + str2 = ', str1 + str2)
print('str1 * 3 =', str1 * 3)
17 What will be the output of following program:
count = 0
for letter in 'Hello World':
if(letter == 'l'):
count += 1
print(count,'letters found')
18 What will be the output of following program:
s="python4csip"
n = len(s)
m=' '
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m + s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m + s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m + '#'
print(m)
19 What will be the output of following program:
a = "Mahender Singh Dhoni"
a = a.split()
b = a[0][0]+". "+a[1][0]+". "+a[2]
print (b)
20 What will be the output of following program:
s='Mahender, Singh, Dhoni'
s1=s.split()
for i in s1:
print(i)
21 What will be the output of following program:
"Welcome to Python4csip.com".split()
22 What will be the output of following program: str
='Hello Python'
print (str)
print (str[0])
print (str[2:8])
print (str[3:])
print (str * 3)
print (str + "String")
23 What will be the output of the program?
line = "PYTHON IS EASY TO LEARN"
L = line.split('a')
for i in L:
print(i, end=' ')
24 What will be the output of following program:
s='mahender, singh, dhoni'
s1=s.split()
for i in s1:
if(i>'n'):
print(i.upper())
else:
print(i)
25 What will be the output of following program:
my_string = 'PYTHON4CSIP'
for i in range(len(my_string)):
print (my_string) my_string='#'
26 What will be the output of following program:
str="Python4csip.com"
for i in range(len(str)):
if(str[i].isalpha()):
print(str[i-1],end='')
if(str[i].isdigit()):
print(str[i],end='')
27 What will be the output of following program:
str="AB145CVD124N"
for i in range(len(str)):
if(str[i].isalpha()):
print(str[i-1],end='')
if(str[i].isdigit()):
print('#',end='')
28 What will be the output of following program:
str="PYTHON4CSIP"
for i in range(len(str)):
if(str[i].isdigit()):
print(str[i],end='')
if(str[i]=='N' or str[i]=='Y'):
print('#',end='')

You might also like