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

DSA in C# | Data Structure and Algorithm using C#

  DSA in C# |  Data Structure and Algorithm using C#: Lecture 1: Introduction to Data Structures and Algorithms (1 Hour) 1.1 What are Data Structures? Data Structures are ways to store and organize data so it can be used efficiently. Think of data structures as containers that hold data in a specific format. Types of Data Structures: Primitive Data Structures : These are basic structures built into the language. Example: int , float , char , bool in C#. Example : csharp int age = 25;  // 'age' stores an integer value. bool isStudent = true;  // 'isStudent' stores a boolean value. Non-Primitive Data Structures : These are more complex and are built using primitive types. They are divided into: Linear : Arrays, Lists, Queues, Stacks (data is arranged in a sequence). Non-Linear : Trees, Graphs (data is connected in more complex ways). Example : // Array is a simple linear data structure int[] number...

Conditional Statement in Python

It is used to solve condition-based problems using if and else block-level statement. it provides a separate block for  if statement, else statement, and elif statement . elif statement is similar to elseif statement of C, C++ and Java languages. Type of Conditional Statement:- 1) Simple if:- We can write a single if statement also in python, it will execute when the condition is true. for example, One real-world problem is here?? we want to display the salary of employees when the salary will be above 10000 otherwise not displayed. Syntax:- if(condition):    statements The solution to the above problem sal = int(input("Enter salary")) if sal>10000:     print("Salary is "+str(sal)) Q)  WAP to increase the salary of employees from 500 if entered salary will be less than 10000 otherwise the same salaries will be displayed. Solution:- x = int(input("enter salary")) if x<10000:     x=x+500 print(x)   Q) WAP to display th...

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