Conditional Expression

 #Example 03_07_2019


a = 35
if(a>5):
    print("the value of a is greater than 5 ")
elif(a>9) :print("the value of a is greater than 9 ")
elif(a>15) : print("the value of a is greater than 15 ")
elif(a>25) :
    print("the value of a is greater than 25 ")
else:
    print(" The value is not grater than 5 and 9") # in this ladder only one statement will execute.

a = 3                   # there is no semicolon in Python, so it takes space automatically , it makes different from other language
if(a>5):                ### here indent will be a "Tab" or "4 space _ _ _ _"
    print("the value of a is greater than 5 ")
elif(a>9) :
    print("the value of a is greater than 9 ")
elif(a>15) :
     print("the value of a is greater than 15 ")
elif(a>25) :
    print("the value of a is greater than 25 ")
else:
    print(" The value is not grater than 5 and 9") # in this ladder only one statement will execute.

a = 22
if(a<5):
    print("the value of a is greater than 5 ")
elif(a>9) :print("the value of a is greater than 9 ")
elif(a>15) : print("the value of a is greater than 15 ")
elif(a>25) :
    print("the value of a is greater than 25 ")
else:
    print(" The value is not grater than 5 and 9")
# in this ladder only one statement will execute.


#################################### Logical Operators

# use of "and", "or' & "not"
'''name= input("Your name please  :")
age= int(input("your age in years   :")) # "int converts input str data to int."
print("Hello....", name)

if(age>25 and age< 45):
    print(" yes, You can work with us your age is in our defined range")
else:
    print("your age is not in our range to work with us, so sorry !  mr.", name)


   ''' #

name= input("Your name please  :")
age= int(input("your age in years   :"))
print("Hello....", name)

if(age>35 or age< 25): #itis use for band reject is here we are not considering age 25 to 35 both includes
    print(" yes, You can work with us your age is in our defined range")
else:
    print("your age is not in our range to work with us, so sorry !  mr.", name)


#####################################

'''# use of in_ & is
# "is" is similar to "=="'''


a = None
if (a is None): # here "is" is similar to ==
    print("YEs")
else:
    print("no")

a = [ 22,  45,  35, 25  ]   # [] is a list

print(35 in a) # it returns true, the 35 is inside the list  if not it returns false

print( 122 in a)# false


############# in is use for loop list tracing. else is optional

# greatest of 4numbers entered by user

num1= int(input("enter first nu.1  :"))   # do typecast  first, by using int
num2= int(input("enter first nu.2 :"))
num3= int(input("enter first nu.3 :"))
num4= int(input("enter first nu.4 :"))


if (num1>num4):
    w1 = num1
else:
    w1 = num4

if(num2> num3):
    w2  = num2
else:
    w2 = num3

if(w1> w2):
    print(str(w1) + "  is greatest")
else:
    print(str(w2)  + "  is greatest")
####it is a comparison method

############################################# 04_07_2019

# a program to find out whether a student is pass or fail, if it requires total 40% and
#  at least 35% in each subject to pass, assume 3 subjects and
#  take marks as an input from the user

name =input(" your name please  :")

sub1 = int(input( " Enter first subject Marks   :"))
sub2 = int(input( " Enter second subject Marks   :"))
sub3 = int(input( " Enter third subject Marks   :"))

if(sub1 < 33 or sub2 < 33 or sub3 <33 ):
    print ( " Dear...", name)
    print( "you are Fail in one of the subjects" )

if ((sub1+ sub2 +sub3)/3 < 40 ):  # two if are used, in place of second if we can use elif but when we use ,80,20,80 the avg is morthan 40 so not work
    print ( " Dear...", name)
    print ("you are fail , you not getting over all 40% in all")
else:
    print ( " Dear...", name)
    print(" congratulations \n you are passed in this Examination")


if(sub1 < 33 or sub2 < 33 or sub3 <33 ):
    print( "you are Fail in one of the subjects" )

elif ((sub1+ sub2 +sub3)/3 < 40 ): # if and elif both do same
    print ("you are fail")
else:
    print("you are passed this exam") #for 80,20,80 avg >40 it works if is not working
   
############################

# A spam comment is defined as a text containing following keywords:
# "make a lot of money", "buy now", "subscribe this", "click this", "make a return call".
# write a program to detect these spams. entered by user

text = input("Enter the spam text  :" )
#print(text)
if ("make a lot of money" in text):
    Spam =True
elif("buy now" in text):
    Spam = True
elif("subscribe this" in text) :
    Spam =True
elif("click this" in text):
    Spam =True
elif("make a return call" in text):
    Spam =True
else :
    Spam = False

if (Spam):
    print("this text is Spam")
else:
    print("this text is not Spam")

################################################

#a program to find whether a given username contains less than 10 characters or not

name = input("Enter your Name  without spacing :")
a=len(name)
print(name)
print ("your name is containing character>")
print( a)
if (a<10 ):
    print( " yes name has less than 10 character ")
elif(a==10):
    print("your name has 10 character")
else:
    print(" name has more than 10 characters")

# note here we enter hhhhhhhreturns it returns 154,  jjjjjjj - 154 sushant-7''' but I solved it

########################

# A program which finds out whether a given name is present in a list or not

names= ["sush", "dinu", "naresh", "chandu", "pragya", "pradeep", "godri" ,"yadu", "rocky", "jaggu", "nitu", "riti", "ritu"  ]

#print(name.sort()) # none returns
#name.sort()

#print(name) #returns ==

#name.sort( reverse = True)
#print(name)

a= input(" enter your name   :")

if a in names:
    print("dear...", a)
    print(" your name is in the list  .")
else :
    print("dear...", a)
    print(" sorry  \n your name is not in this list.")

########################

# A program to calculate the grade of a student from his marks from the folloing scheme
#  90-100--A+, 80-90-- A, 70-80--B+, 60*70--B,


name = input("Enter your name    :")
marks = int(input("enter your marks....: "))
'''
if 100>=marks>=90:
    print("dear....",name)
    print(" You score is 'A++' Grade in this examination ")
elif 90>marks>=80:
    print("dear....",name)
    print(" You score is 'A+' Grade in this examination")
elif 80>marks>=70:
    print("dear....",name)
    print(" You score is 'A' Grade in this examination")
elif 70>marks>=60:
    print("dear....",name)
    print(" You score  is 'B+' Grade in this examination")
elif 600>marks>=50:
    print("dear....",name)
    print(" You schore is 'B' Grade in this examination")
elif 50>marks>=40:
    print("dear....",name)
    print(" You score is 'c' Grade in this examination")
else:
    print("dear....",name)
    print(" You score IS 'D' Grade in this examination. \n you not passed the Examination.")'''

if marks>100:
    print("Enter a valid number you scored in this examination ie- 0-100")

elif 100>=marks>=90:
    grade="A++"
elif 90>marks>=80:
    grade="A+"
elif 80>marks>=70:
    grade="A"
elif 70>marks>=60:
    grade="B+"
elif 60>marks>=50:
    grade="B"
elif 50>marks>=40:
    grade="C"
else:
    grade = "Fail"
print("your grade is " + grade)


#################################

#A program to find out whether a given post is talking about Sushant or not

post = input("enter your post   :")
if "Sush" in post:
    print("yes ...they talking about you1")
elif "sush" in post :
    print("yes ...they talking about you 2")
elif "SUSH" in post :
    print("yes ...they talking about you 2")

# here we can find in which line they are talking about by using line identification.

#  here we did character matching mechanism . 

######
# Write a program to print Yes when the age entered by the user is grater than or equal to 18.

name= input(" Enter your name  : ")
a = int(input(" Enter your Age in years   :"))

print( " hello.. ", name)
#print(" your age is > ", a) # this > is not working  ##### single '=' is use to assign anything
print( "your Age is :", a)
if( a > 18):
    print("yes  you can participate in Assembly Election") ###  relation operator == is equals, >= is greater then / equal to, <= less/equal
elif(a==18) :
    print ("your age is 18 years so you have to apply for voting card")
  #  print("your age is exact= 18") # later I have to check why this line is thrown error int(); I had solved this, how I did it I does not know
else :
    print("You can not participate in assembly election, you do not qualify the age criteria.")


########sushant401@hotmail.com,


Comments

Popular posts from this blog

Game_01_Snake_Water_Gun_or_Rock_Paper_Scissor

String Function