Skip to main content

Conditional Statement in Python

Conditional Statement in Python


This Statement is used to solve the condition based program using if,elif, and else statement.


It provides a block-level statement to write code without using curly brackets. Block will be managed by indent.


Indent provides structure to write code using the outer statement and inner statement.
all parallel statements of the same indent will work as an outer and after press tab or space it will be an inner indent.


if condition:
  statement  //inner statement
statement//outer statement


 Type of Conditional Statement:-


1 If:- when the condition will be true then we can use simple if statement

if condition:
  statement1
  statement2



2 If--else:-

it will work when the condition is true or false.

if condition:
   statement1
   statement2
else:
   statement1
   statement2


WAP to increase mark of a student with five grace marks if the entered subject mark is <33 otherwise the same mark will be displayed?

3 Nested if-else:-

   it is used to solve more than one condition based problem without using the logical operator.
   nested should not be preferred for the complex conditions because python not provide block-level syntax easily.

if condition:
   if condition:
      statement
   else:
     statement
else:
  if condition:
     statement
  else:
     statement

WAP to check divisibility from 3 and 5 both of any entered numbers without using logic and operator?

num = int(input("enter number"))
if num%3==0:
    if num%5==0:
        print("divisible by 3 and 5 both")
    else:
        print("Only divisible by 3 not five")
else:
    if num%5==0:
     print("divisible by 5")
    else:
     print("not divisible by 3 and 5") 


4 Ladder if--else:-


Ladder means step by step, it will execute the first if statement when it will false then process to next
statement continuously when none of the statements will be true then it will execute else statement.

if condition:
  statement
elif condition:
 statement
elif condition:
 statement
else:
 statement


Q) WAP to check vowel and consonant using nested and ladder both?

Q) WAP to Calculate Marksheet using five different subjects with the following condition.

1 all subject marks should be 0 to 100.

2 if only one subject mark is <33 then suppl.

3 if all subject marks is >33 then percentage and division should be calculated.

4 if a student is suppl then five bonus mark can be applied to the student to be pass then the student will be passed by grace.

5 Display Grace Subject name, distinction subject name,suppl subject name and failed subject name.



Q) WAP to check the greatest using four different numbers using a ladder and nested both?






5 Multiple If:-


Multiple Condition with multiple results.

WAP to check divisibility of number that number is divisible by 3,5 and 9 with all combinations?

17



.................................................................................

WAP to check leap year?

WAP to check the greater number?

WAP to find a middle number in three different numbers?

WAP to check the greatest number?

WAP to check that salary is in income tax criteria or not .if in income tax then display income tax slave.




Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. ## programm for making a marksheet in python

    maths = int(input("Enter maths marks: "))
    science = int(input("Enter science marks: "))
    english = int(input("Enter english marks: "))
    hindi = int(input("Enter hindi marks: "))
    social_science = int(input("Enter social science marks: "))

    m = maths
    s = science
    e = english
    h = hindi
    sc = social_science

    marks1 = m, s, e, h, sc
    marks = m + s + e + h + sc
    average = float((m + s + e + h + sc)/5)
    total = 500
    ##print(marks)
    ##print(marks, "out of ", total)
    ##print(average)


    if (m>0 and m<100) and (s>0 and s<100) and (e>0 and e<100) and (h>0 and h<100) and (sc>0 and sc<100):

    if m<28:
    print("fail in maths")

    if s<28:
    print("fail in science")

    if e<28:
    print("fail in english")

    if h<28:
    print("fail in hindi")

    if sc<28:
    print("fail in social science")

    #if (m>=33 and m<100) and (s>=33 and s<100) and (e>=33 and e<100) and (h>=33 and h<100) and (sc>=33 and sc<100):
    # print(average)
    # print(marks, "out of ", total)





    if m<33 and m>28:
    m = m + (33 - m)
    print("pass with grace in maths")

    if s<33 and s>28:
    s = s + (33 - s)
    print("pass with grace in science")

    if e<33 and e>28:
    e = e + (33 - e)
    print("pass with grace in english")

    if h<33 and h>28:
    h = h + (33 - h)
    print("pass with grace in hindi")

    if sc<33 and sc>28:
    sc = sc + (33 - sc)
    print("pass with grace in social science")




    if m<60 and m>=33:
    print("pass in maths")

    if s<60 and s>=33:
    print("pass in science")

    if e<60 and e>=33:
    print("pass in english")

    if h<60 and h>=33:
    print("pass in hindi")

    if sc<60 and sc>=33:
    print("pass in social science")




    if m<100 and m>=60:
    print("pass in maths with distinction")

    if s<100 and s>=60:
    print("pass in science with distinction")

    if e<100 and e>=60:
    print("pass in english with distinction")

    if h<100 and h>=60:
    print("pass in hindi with distinction")

    if sc<100 and sc>=60:
    print("pass in social science with distinction")



    if (m<=50 and m>33) and (s<=50 and s>33) and (e<=50 and e>33) and (h<=50 and h>33) and (sc<=50 and sc>33):

    print("pass in all subject with C grade")


    if (m<=75 and m>50) and (s<=75 and s>50) and (e<=75 and e>50) and (h<=75 and h>50) and (sc<=75 and sc>50):

    print("pass in all subject with B grade")

    if (m<=100 and m>75) and (s<=100 and s>75) and (e<=100 and e>75) and (h<=100 and h>75) and (sc<=100 and sc>75):

    print("pass in all subject with A grade")

    print("\n\nYour marks is: ", marks)
    print("total marks obtained", marks, "out of ", total, "marks")
    print("Your overall percentage is", average,"%")

    '''
    if average<=33 and average>50:
    print("pass in all subject with c grade")

    if average<=50 and average>75:
    print("pass in all subject with b grade")

    if average<=75 and average>100:
    print("pass in all subject with a grade")

    '''



    else:
    print("marks is not real")

    ReplyDelete

Post a Comment

POST Answer of Questions and ASK to Doubt

Popular posts from this blog

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

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

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