Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

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.




2 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  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

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post