التخطي إلى المحتوى الرئيسي

Break,Continue and Pass Statement in Python


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):
    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
{
}
for i in range(1,10):
   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.

تعليقات

  1. """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.
    """

    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()

    ردحذف
    الردود
    1. This will be much better as compare to that program
      sal = 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)

      حذف
  2. 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---->>

    sal=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)

    ردحذف
  3. Sir in my program output is--
    enter 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?

    ردحذف
  4. 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.
    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)


    ردحذف
  5. #MOHIT CHOUHAN
    salary=int(input("Enter your Salary : "))

    for empid in range(1001,1021):

    if salary>20000 and empid>1017:
    break
    if empid==1003 or empid==1005 or empid==1007:
    continue
    if empid==1013 or empid==1015:
    day=(salary/30)*2
    Deduct=salary-day
    print(empid,Deduct)
    else:
    print(empid,salary)

    ردحذف
  6. #Vishal Baghel#

    salary = int(input("Enter Employees Salary = "))
    for i in range(1001,1021):
    if i>1017 and salary>20000:
    break
    if i==1003 or i==1005 or i==1007:
    continue
    elif i==1013 or i==1015:
    p_day = salary//30
    print("Employee_ID = ",i,"Salary After 2 Days Salary Deduced = ",salary-p_day*2)
    else:
    print("Employee_ID = ",i,"Salary is = ",salary )

    ردحذف
  7. #Shivam Shukla
    #1.1) Assignment Solution
    sal=int(input("Enter a Salary : "));
    cutsal=sal-((sal/30)*2);
    s = 1018 if(sal>20000) else 1021;
    for i in range(1001,s):
    if(i==1003 or i==1005 or i==1007):
    continue;
    if(i==1013 or i==1015):
    print("EmpId :",i,cutsal);
    continue;
    print("EmpId :",i,sal);

    ردحذف
  8. #Shivam Shukla
    #1.2) Assignment Solution
    sal=int(input("Enter a Salary : "));
    cutsal=sal-((sal/30)*2);
    for i in range(1001,1021):
    if(sal>20000 and i==1018):
    break;
    if(i==1003 or i==1005 or i==1007):
    continue;
    if(i==1013 or i==1015):
    print("EmpId :",i,cutsal);
    continue;
    print("EmpId :",i,sal);

    ردحذف
  9. sal=int(input("enter a number"))
    ds=sal//30
    if sal>20000:
    for i in range(1001,1018):
    if i==1013 or i==1015:
    print(i," salary is",sal-(ds*2))
    if i==1003 or i==1005 or i==1007 or i==1013 or i==1015:
    continue;
    print(i,"salary is",sal)
    if sal<20000:
    for i in range(1001,1021):
    if i==1003 or i==1005 or i==1007:
    continue;
    print(i,"salary is",sal)

    ردحذف
  10. 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.

    salary = int(input("enter salary of employee : "))
    for emyid in range(1001,1021):
    if salary>=20000 and emyid>1017:
    break
    if emyid==1003 or emyid==1005 or emyid==1007:
    continue
    if emyid==1013 or emyid==1015:
    deducteddsal = (salary/30)*2
    print("emyid ",emyid, "salary is % .2f " % (salary-deducteddsal))
    else:
    print("emyid ",emyid, "salary is ",salary)

    ردحذف
  11. salary=int(input("Enter salary "))
    for i in range(1001,1021):
    if salary>20000 and i>1017:
    break
    elif i==1003 or i==1005 or i==1007:
    continue
    elif i==1013 or i==1015:
    dsalary=salary-(2*(salary//30))
    print("EmpID "+str(i)+" salary after deduction "+str(dsalary))

    else:
    print("EmpID "+str(i)+" salary "+str(salary))

    ردحذف
  12. '''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.'''

    salary=int(input("enter salary"))
    dstwodays=(salary//30)*2
    for i in range(1001,1021):
    if i>1017 and salary>20000:
    break
    if i==1003 or i==1005 or i==1007:
    continue
    elif i==1013 or i==1015:
    print(i,"salary",salary-dstwodays)
    else:
    print(i,"salary",salary)

    ردحذف
  13. #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.

    salary =22000
    for empid in range (1001,1021):
    if salary>=20000 and empid>1017:
    break
    if empid ==1003 or empid ==1005 or empid ==1007:
    continue
    elif empid==1013 or empid==1015:
    dsal=(salary/30)*2
    salary1=salary-dsal

    print("empid ",empid,"salary is",salary1)
    else:

    print("empid",empid,"salary is",salary)




    ردحذف
  14. salary=int(input("enter salary"))
    deduceds=(salary//30)*2
    for i in range(1001,1021):
    if i==1017 and salary>20000:
    break
    if i==1003 or i==1005 or i==1007:
    continue
    elif i==1013 or i==1015:
    print(i,"salary",salary-deduceds)
    else:
    print(i,"salary",salary)

    ردحذف
  15. #continue program
    for i in range(1,11):
    if i==3 and i==5:
    continue
    print(i)
    print("hello")

    ردحذف

إرسال تعليق

POST Answer of Questions and ASK to Doubt

المشاركات الشائعة من هذه المدونة

Uncontrolled form input in React-JS

  Uncontrolled form input in React-JS? If we want to take input from users without any separate event handling then we can uncontrolled the data binding technique. The uncontrolled input is similar to the traditional HTML form inputs. The DOM itself handles the form data. Here, the HTML elements maintain their own state that will be updated when the input value changes. To write an uncontrolled component, you need to use a ref to get form values from the DOM. In other words, there is no need to write an event handler for every state update. You can use a ref to access the input field value of the form from the DOM. Example of Uncontrolled Form Input:- import React from "react" ; export class Info extends React . Component {     constructor ( props )     {         super ( props );         this . fun = this . fun . bind ( this ); //event method binding         this . input = React . createRef ();...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

JDBC using JSP and Servlet

JDBC means Java Database Connectivity ,It is intermediates from Application to database. JDBC has different type of divers and provides to communicate from database server. JDBC contain four different type of approach to communicate with Database Type 1:- JDBC-ODBC Driver Type2:- JDBC Vendor specific Type3 :- JDBC Network Specific Type4:- JDBC Client-Server based Driver  or JAVA thin driver:- Mostly we prefer Type 4 type of Driver to communicate with database server. Step for JDBC:- 1  Create Database using MYSQL ,ORACLE ,MS-SQL or any other database 2   Create Table using database server 3   Create Form according to database table 4  Submit Form and get form data into servlet 5  write JDBC Code:-     5.1)   import package    import java.sql.*     5.2)  Add JDBC Driver according to database ide tools     5.3)  call driver in program         ...