Break, Continue and Pass Statement in Python:-
Break:- It is used to manually terminate the loop based on condition, the break statement always will be defined by the Conditional Statement in Loop.
for i in range(1,10):
if i==3:
break;
print(i)
output:- 1
2
Continue:- It is used to skip the particular data from the loop and continue the process of the loop.
for i in range(1,10):
if i==3:
continue
print(i)
output:- 1
2
4
5
6
7
8
9
the important question of break and continue:-
for i in range(1,10):
if i==3 and i==5:
continue
print(i)
print("hello")
..................................
for i in range(1,10):
pass
Break:- It is used to manually terminate the loop based on condition, the break statement always will be defined by the Conditional Statement in Loop.
for i in range(1,10):
if i==3:
break;
print(i)
output:- 1
2
Continue:- It is used to skip the particular data from the loop and continue the process of the loop.
for i in range(1,10):
if i==3:
continue
print(i)
output:- 1
2
4
5
6
7
8
9
the important question of break and continue:-
for i in range(1,10):
if i==3 and i==5:
continue
print(i)
print("hello")
..................................
for i in range(1,10):
if i==3 and i==5:
break
print(i)
print("hello")
for i in range(1,10):
if i==3 or i==5:
continue
print(i)
print("hello")
........................................................................
pass:-
it is used to define an empty block in python because python does not use braces means if we want to only define method structure, a loop structure, if-else structure empty then we can use pass statement
for(i=1;i<=10;i++) #C empty loop
{
}
pass
Assignment of Loop:-
WAP to display the salary of employees where empid will be started from 1001 to 1020.
empid 1003,1005 and 1007 salary should not be displayed,empid 1013 and 1015,2 days salary should be deduced, if the entered salary is above 20000 then the calculation will be performed till 1017.
A salary is common for all employees.
"""WAP to display the salary of employees where empid will be started from 1001 to 1020.
ReplyDeleteempid 1003,1005 and 1007 salary should not be displayed,empid 1013 and 1015,2 days salary should be deduced, if the entered salary is above 20000 then the calculation will be performed till 1017.
A salary is common for all employees.
"""
salary=30000
perdaysalary=salary//30
p=perdaysalary
for i in range(1001,1021):
if i==1003 or i==1005 or i==1007:
continue
print("empid",i,end=''+"salary="+str(salary)+'\n')
if i==1013 :
print("empid",i,end=''+"salary="+str(salary-p)+'\n')
elif i==1015:
print("empid",i,end=''+"salary="+str(salary-p)+'\n')
s=int(input("enter salary"))
for j in range(1001,1018):
if s>20000:
print("empid",j,end=''+"salary="+str(s)+'\n')
else:
print("salary less than 20000")
print()
This will be much better as compare to that program
Deletesal = int(input("enter salary of employee"))
for empid in range(1001,1021):
if sal>=20000 and empid>1017:
break
if empid==1003 or empid==1005 or empid==1007:
continue
elif empid==1013 or empid==1015:
dsal = (sal/30)*2
print("empid ",empid, "salary is ",sal-dsal)
else:
print("empid ",empid, "salary is ",sal)
Program to display the salary of employees where empid will be started from 1001 to 1020.empid 1003,1005 and 1007 salary should not be displayed,empid 1013 and 1015,2 days salary should be deduced, if the entered salary is above 20000 then the calculation will be performed till 1017---->>
ReplyDeletesal=int(input("enter salary of employee"))
pds=sal/30 #pds=per day salary
rsal=sal-pds*2
for empid in range(1001,1021):
if sal>20000 and empid>1017:
break
if empid==1003 or empid==1005 or empid==1007:
continue
elif empid==1013 or empid==1015:
rsal=sal-pds*2
print("empid",empid,"salary is",rsal)
else:
print("empid",empid,"sal is",sal)
Sir in my program output is--
ReplyDeleteenter salary of employee13654
empid 1001 salary is 12743.733333333334
empid 1002 salary is 12743.733333333334
empid 1004 salary is 12743.733333333334
empid 1006 salary is 12743.733333333334
empid 1008 salary is 12743.733333333334
empid 1009 salary is 12743.733333333334
empid 1010 salary is 12743.733333333334
empid 1011 salary is 12743.733333333334
empid 1012 salary is 12743.733333333334
empid 1014 salary is 12743.733333333334
empid 1016 salary is 12743.733333333334
empid 1017 salary is 12743.733333333334
empid 1018 salary is 12743.733333333334
empid 1019 salary is 12743.733333333334
empid 1020 salary is 12743.733333333334
which is not according to given condition,in output empid-1013 and 1015's salary should be reduced but it is not executed in output.Both these empid is not executing in output.What is the correction?
WAP to display the salary of employees where empid will be started from 1001 to 1020.
ReplyDeleteempid 1003,1005 and 1007 salary should not be displayed,empid 1013 and 1015,2 days salary should be deduced, if the entered salary is above 20000 then the calculation will be performed till 1017.
A salary is common for all employees.
start = 1001
end = 1020
salary =int(input("Enter salary = "))
for empid in range(start, end+1):
if empid == 1003 or empid==1005 or empid == 1007:
continue
elif empid == 1013 or empid == 1015:
x =salary/30
l = 2*x
print(str(empid)+ ' = ' + str(salary-l) +str(" leave has been deducted"))
elif salary >= 20000 and empid == 1017:
print(empid,"=",salary)
break
else:
print(empid,"=",salary)
Post a Comment
If you have any doubt in programming or join online classes then you can contact us by comment .