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

Ternary operator in python


It is used to solve a condition-based program using a single-line statement. ternary operator contains an if-else statement using a single line.
It is used to solve a condition-based program using a single-line statement.
Syntax:-
var =  True statement if condition else false statement
print(var if condition else var)
Example of a ternary operator in Python?
Q) WAP to check the greater number using Ternary Operator?
Solution First:-
a = int(input("enter first number"))
b = int(input("enter second number"))
res =  "a is greater" if a>b else "b is greater"
print(res)
Solution Second:-
a = int(input("enter first number"))
b = int(input("enter second number"))
print(a if a>b else b)
WAP to check vowel and consonant using a ternary operator?
s = input("enter char to check vowel and consonent")
o = "Vowel" if s=='a' or s=='e' or s=='i' or s=='o' or s=='u' else "Consonent"
print(o)
Nested Ternary:-
We can create more than one Ternary Statement using a nested sequence.
var =  (True if condition else false) if condition else (True if condition else false)
 Example of Nested ternary:-
WAP to calculate the greatest number using a ternary operator in Python?
a = int(input("enter first number"))
b = int(input("enter second number"))
c = int(input("enter third number"))
res =   "a is greatest" if a>c else "c is greatest" if a>b  else "b is greatest" if b>c else "c is greatest"
print(res)
Advantage:-
Its performance is better if we can solve expression using a single line
Disadvantage:-
It is not used to solve complex condition-based or multiple lines based program logic.
Assignment of Ternary Operator:-
1) WAP to check leap year using a ternary operator in Python?
 Solution:-
year  = int(input("enter year"))
s = "Leap year" if(year%400==0 or (year%4==0)  and  (year%100!=0) ) else "NOT Leap year"
print(s)
2)  WAP to check divisibility of number that it is divisible by 3 and 5 or not?
Solution:-
num = int(input("enter number"))
s = "divisible" if num%3==0 and num%5==0 else "not divisible"
print(s)
3)  WAP to check divisibility of a number by 3 and 5, individually and both?
num = int(input("enter number"))
s = "divisible by 3 and 5" if num%3==0 and num%5==0 else "divisible by 3" if num%3==0 else "diviblle by 5 " if num%5==0 else "not divisble by 3 and 5"
print(s)
4)  WAP to check that salary is in income tax or not display the total amount and the taxable amount 
sal = int(input("enter salary"))
s = "not taxable" if sal<=250000 else "Tax amount is " + str(sal-250000)
print(s)
5)  WAP to calculate electricity bill where unit price, total consumption will be entered by the user, if the bill is <400 then pay only 100 RS and above this 50% amount will be paid.
Solution:-
up = float(input("enter unit price"))
con = float(input("enter consumption"))
total = up*con
s = "pay only 100 rs " if total<400 else  "Actual bill is " + str(total) + "payble bill is " + str(total/2)
print(s)

تعليقات

  1. #check leap year using a ternary operator in Python?

    year = int(input("Please Enter the Year : "))

    if (( year%400 == 0)or (( year%4 == 0 ) and ( year%100 != 0))):
    print("%d is a Leap Year" %year)
    else:
    print("%d is Not the Leap Year" %year)

    ردحذف
  2. # check divisibility of number that it is divisible by 3 and 5 or not?

    number = int(input("Please Enter the Number : "))

    if (( number%3 == 0)or (( number%5 == 0 ))):
    print("%d is a divisible number" %number)
    else:
    print("%d is not a divisible number" %number)

    ردحذف
  3. Greater number program uisng ternary operator
    a=int(input("Enter first number"))
    b= int(input("Enter first number"))
    s = str(a)+" is greater" if a>b else str(b)+" is greater"
    print(s)

    ردحذف
  4. Lokesh Rathore

    Check divisibility of number that it is divisible by 3 and 5 or not ?
    Solution:-
    num = int(input("Enter the Number :- "))
    a="Divisible by 3 and 5" if num%3==0 and num%5==0 else "Divisible by 3" if num%3==0 else "Divisible by 5" if num%5==0 else "Not divisible by 3 and 5"
    print(a)

    ردحذف
  5. Lokesh Rathore

    Check leap year using a ternary operator in Python ?
    Solution :-
    year = int(input("Enter Year :-"))
    a = "This is Leap Year." if (year%4==0) else "This is Not Leap Year."
    print(a)

    ردحذف
  6. Lokesh Rathore

    check that salary is in income tax or not ?
    Solution :-
    sal = int(input("Enter the Salary :- "))
    a="Salary is Not Taxable." if (sal<=250000) else "Salary is Taxable."
    print(a)


    ردحذف
  7. Lokesh Rathore

    Check the greater number using Ternary Operator ?
    Solution :-
    a = int(input("Enter first number :- "))
    b = int(input("Enter second number :- "))
    s = "A is greater number." if a>b else "B is greater number."
    print(s)

    ردحذف
  8. Lokesh Rathore

    Check vowel and consonant using a ternary operator ?
    Solution :-
    char = input("Enter Character to check Vowel and Consonent : - ")
    r = "It is Vowel." if char=="a" or char=="e" or char=="i" or char=="o" or char=="u" else " It is Consonent."
    print(r)

    ردحذف
  9. Lokesh Rathore

    Calculate the greatest number using a ternary operator in Python ?
    Solution :-
    a = int(input("Enter first number :- "))
    b = int(input("Enter second number :- "))
    c = int(input("Enter third number :- "))
    s = "A is Greatest Number." if a>c else "C is Greatest Number." if a>b else "B is Greatest Number." if b>c else "C is Greatest Number."
    print(s)

    ردحذف
  10. deependra singh jadaun4 نوفمبر 2020 في 8:43 م

    program for income tax ,salay ,taxable amount
    s=int(input("enter the salary"))
    i=s-250000
    r="salary is in income tax "if s>250000 else"salary is not in income tax"
    print(r)
    p=(0.1*i)# this much of tax is payable
    print("'{0}' salary amount is taxable and '{1}' is payable as tax amount " .format(i,p))

    ردحذف
  11. deependra singh jadaun6 نوفمبر 2020 في 11:08 ص


    WAP to calculate the greatest number using a ternary operator in Python?

    WAP to calculate the greatest number using a ternary operator in Python?

    a=10
    b=15
    c=20
    s="'a is greatest' if a>c else 'c is greatest' "if a>b else "b is greatest"if b>c else "c is greatest"
    print(s)

    ردحذف
  12. deependra singh jadaun6 نوفمبر 2020 في 11:11 ص

    WAP to check divisibility of number that it is divisible by 3 and 5 or not?
    a=int(input(" enter any no. "))
    s="number is divisible by 3 or 5" if a%3==0 or a%5==0 else "no. is not divisible"
    print(s)

    ردحذف
  13. Parag Jaiswal
    1) WAP to check leap year using a ternary operator in Python?

    year = int(input("Enter year"))
    res ="A leap year" if(year%4==0) else "Not a leap year"

    print(year, res)

    ردحذف
    الردود
    1. not correct because leap year is divisible by 400,4 and not divisible by 100

      حذف
  14. Parag Jaiswal
    2) WAP to check divisibility of number that it is divisible by 3 and 5 or not?
    n = int(input("Enter number = "))

    res= " Divisible by 3 & 5" if(n%3 == 0 and n%5==0) else "Divisible by 3" if(n%3==0) else "Divisible by 5" if(n%5==0) else "Not divisible by 3 & 5"

    print(n, res)

    ردحذف
  15. Parag Jaiswal
    #WAP to check that salary is in income tax or not display the total amount and the taxable amount
    s = int(input("Enter your salary = "))

    r = "salary is not taxable" if s<= 500000 else "Salary is taxable and tax amount is " +str(s-500000)
    print(r)

    ردحذف
  16. Parag Jaiswal
    #WAP to calculate electricity bill where unit price, total consumption will be entered by the user, if the bill is <400 then pay only 100 RS and above this 50% amount will be paid.
    price = int(input("Enter unit price = "))
    con = int(input("Enter consumption = "))

    total = price * con

    z= "Bill is 100 " if total<=400 else "Total bill is " +str(total) +"Payable bill is "+str(total/2)
    print(z)

    ردحذف
  17. Adarsh dixit
    year=int(input('enter year'))
    s = "leap year"if(year%4==0)else"not leap year"
    print(s)

    ردحذف
  18. #Mohit Chouhan
    1.
    s=int(input("Enter the Year : "))
    w="leap year" if s/4==0 else "not a leap year"
    print(w)

    # 2.
    s=int(input("Enter the number to check : "))
    r="Yes it's divisable " if s%3==0 and s%5==0 else"Not divisable"
    print(r)

    3.
    f=int(input("Enter the number : "))
    h="Yes its divisible by 3 & 5 both " if f%3==0 and f%5==0 else "divisible by 3 "if f%3==0 else "divible by 5 " if f%5==0 else"not divisible by 3 & 5 both "
    print(h)

    4.
    sal=int(input("Enter the salary to check : "))
    t="YOu need to pay Amount"+str (sal-35000) if sal>=350000 else "Tax free "
    print(t)

    5.
    up=int(input("Enter unit price: "))
    com=int(input("Enter unit comm: "))
    r=up*com
    e = "Pay only 100 rs " if r<400 else "bill " +str(r)+" pay bill "+str(r/2)
    print(e)

    ردحذف
  19. #1) WAP to check leap year using a ternary operator in Python?
    year= int(input("give an year"))
    num= "leap year" if(year%400==0 or(year%4==0) and (year%100!=0)) else "not a leap year"
    print(num)

    ردحذف
  20. y=int(input("enter the year = "))
    a="leap year" if (y%4==0) and (y%100!=0) else "not leap year" if (y%100==0) else "leap year" if(y%400==0) else "not leap year"
    print(a)

    ردحذف
  21. N=int(input("Enter the Number= "))
    a="divisible" if ((N%3==0) and (N%5==0)) else "not"
    print(a)

    ردحذف
  22. to check that salary is in income tax or not display the total amount and the taxable amount ?

    s=int(input("Enter the salary = "))
    A="Tax free" if s<=250000 else "Taxable tax amount is = " + str(s-250000)
    print(A)
    print("total salary = ",s)

    # WAP to check divisibility of a number by 3 and 5, individually and both?

    N=int(input("Enter the Number= "))
    a="divisible by 3 & 5" if ((N%3==0) and (N%5==0)) else "divisible by 3" if (N%3==0) else "divisible by 5" if (N%5==0) else "not divisible by both"
    print(a)

    #WAP to calculate electricity bill where unit price, total consumption will be entered by the user, if the bill is <400 then pay only 100 RS and above this 50% amount will be paid.

    UnitPrice=float(input("enter the unit price = "))
    consumption=float(input("enter the total consumption= "))
    TotalBill=UnitPrice*consumption
    Q="pay only 100 rs" if (TotalBill<400) else "actual bill is = "+str(TotalBill)+"Payble bill is = "+str(TotalBill/2)
    print(Q)

    ردحذف
  23. #NIKHIL SINGH CHOUHAN

    #WAP to check divisibility of number that it is divisible by 3 and 5 or not?
    i=int(input("enter number"))
    v= "it is divisible by 3 and 5"if(i%3==0)and(i%5==0)else"ths number is divisible by 3 "if(i%3==0)else"number is divisible by 5"if(i%5==0)else"number is not divisible by 3 or 5"
    print(v)

    ردحذف
  24. #NIKHIL SINGH CHOUHAN

    # WAP to check leap year using a ternary operator in Python?
    i=int(input("enter year"))
    a="this year is leap year"if(i%4==0)and(i%100!=0)or(i%400!=0)else"this year is not leap year"
    print(a)

    ردحذف
  25. #Check Leap Year By Surendra
    year = int(input("Enter Year"))
    var = "This is Leap Year" if (year%400==0) or (year%4==0) and (year%100!=0)else "This is Not leap year"
    print(var)

    ردحذف
  26. #Check Leap Year By Surendra
    year = int(input("Enter Year"))
    var = "This is Leap Year" if (year%400==0) or (year%4==0) and (year%100!=0)else "This is Not leap year"
    print(var)

    ردحذف
  27. num= int(input("write a number to chack if no is divisible by 3 or 5"))
    x="number is divisible by 3 and 5" if( num%3==0 and num%5==0) else "number is not divisible by 3 and 5"
    print(x)

    ردحذف
  28. num= int(input("write a number to chack if no is divisible by 3 or 5"))
    x="number is divisible by 3 and 5" if( num%3==0 and num%5==0) else "number is divisible by 3"if num%3==0 else "number is divisible by 5" if num%5==0 else "number is not divisible by 3 or 5 and both"
    print(x)

    ردحذف
  29. salary= int (input("write down your salary"))
    x="not taxable" if salary <=250000 else "taxable amount is"+str(salary-250000)
    print(x)

    ردحذف
  30. #Q) WAP to check the greater number using Ternary Operator?
    x=int(input("Enter a value of x : "))
    y=int(input("Enter a value of y : "))
    z=int(input("Enter a value of z : "))
    print(x) if(x>y and x>z) else print(y) if(y>z) else print(z)

    ردحذف
  31. #Q) WAP to check vowel and consonant using a ternary operator??
    ch1=input("Enter Char : ")
    k= 1 if((ord(ch1)>=65 and ord(ch1)<=90) or (ord(ch1)>=97 and ord(ch1)<=122 )) else 0
    exit(0) if(k==0) else print()
    ch = chr(ord(ch1)+32) if ord(ch1)>=65 and ord(ch1)<=90 else ch1
    print("vowel") if ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u' else print("consonent")

    ردحذف
  32. #1) WAP to check leap year using a ternary operator in Python?
    year=int(input("enter year : "))
    print("yaa, this is a leap year.....") if(year%4==0 or year%400==0 and year%100==0) else print("No Noo, this is not a leap year.....")

    ردحذف
  33. #2) WAP to check divisibility of number that it is divisible by 3 and 5 or not?
    no=int(input("Enter number : "))
    print("yaaa! this value is divisible.....") if(no%3==0 or no%5==0) else print("No Noo! this value is not divisible.....")

    ردحذف
  34. #3) WAP to check divisibility of a number by 3 and 5, individually and both?
    no=int(input("enter a number "))
    print("this number is not divisible by both.....") if(not(no%3==0 or no%5==0)) else print("this number is divisible by both 3 nd 5.....") if(no%3==0 and no%5==0) else print("this number is not divisible by both, only with 3....") if(no%3==0) else print("this number is not divisible by both, only with 5....")

    ردحذف
  35. #4) WAP to check that salary is in income tax or not display the total amount and the taxable amount.
    slry= int(input("enter salary : "))
    print("Tax amount is " + str(slry-250000) ) if(not(slry<=250000)) else print("No Noo, It's not taxable ammount.....")

    ردحذف
  36. #5) WAP to calculate electricity bill where unit price, total consumption will be entered by the user, if the bill is <400 then pay only 100 RS and above this 50% amount will be paid.
    unitp = float(input("enter unit price : "))
    tcons = float(input("enter consumption : "))
    total = unitp*tcons
    print("you pay only 100'rs.....") if total<400 else print(" there is actual bill ammount is " + str(total) + " but don't worry, payble bill ammount is " + str(total/2) + "!")

    ردحذف
  37. num1=int(input("enter first number"))
    num2=int(input("enter second number"))
    greater="num1 is greater" if num1>num2 else "num2 is greater"
    print(greater)

    ردحذف
  38. year=int(input("enter a year"))
    x="leap year"if(year%400==0 or (year%4==0) and (year%100!=0)) else "not leap year"
    print(x)

    ردحذف
  39. to calculate electricity bill where unit price, total consumption will be entered by the user, if the bill is <400 then pay only 100 RS and above this 50% amount will be paid

    unit = float(input("enter unit price"))
    consumption = float(input("enter consumption"))
    total = unit*consumption

    s = 'pay only 100 rs ' if total<400 else 'Actual bill is ' + str(total) + 'payble bill is ' + str(total/2)

    print(s)

    ردحذف
  40. number= int(input("enter number"))
    x= "divisible by 3 and 5" if number%3==0 and number%5==0 else "divisible by 3" if number%3==0 else "divislle by 5 " if number%5==0 else "not divisble by 3 and 5"

    print(x)

    ردحذف
  41. '''WAP to check leap year using a ternary operator in Python?'''
    y=int(input("enter year:-"))
    print("leap year" if y%4==0 or y%400==0 and y%100!=0 else "not leap year")

    ردحذف
  42. I think there is some problem with that question of tax.Do check for the big amounts.

    ردحذف
  43. # WAP to calculate electricity bill where unit price, total consumption will be entered by the user, if the bill is <400 then pay only 100 RS and above this 50% amount will be paid.
    # Mayank Sonwani


    unitprice=float(input("Enter the rate of an unit "))
    consumption=float(input("Consumption of the month "))
    bill=float(unitprice*consumption)
    print("Pay only Rs.100 to clear your bill " if bill<400 else "Bill amount is " +str(bill)+" and you need to pay only 0" +str(bill/2) )

    ردحذف
  44. #Leap Year
    #Mayank Sonwani

    year=int(input("Enter the year to check if it is leap or not: "))
    print("Entered year is a leap year" if year%400==0 or year%4==0 and year%100!=0 else "Entered year is not a leap year")

    ردحذف
  45. #find leap year or not

    a=int(input("find leap year"))
    year="leap year" if (a%4==0) or (a%400==0) and (a%100!=0) else "normal year"
    print(year)

    ردحذف
  46. #find a year is leap year or not

    a=int(input("leap year"))
    year="leap year" if (a%4==0) or (a%400==0) and (a%100!=0) else "normal year"
    print(year)

    ردحذف
  47. #WAP to check divisibility of number that it is divisible by 3 and 5 or not?

    a=int(input("enter divisible value"))
    s="divisible value" if (a%3==0) and (a%5==0) else "not divisible"
    print(s)

    ردحذف
  48. #find Divisible value or not

    x=int(input("enter divisible value"))
    s="divisible value" if (x%2==0) or (x%4==0) else "not divisible"
    print(s)

    ردحذف
  49. #WAP to check leap year using ternary operator
    year=int(input("enter year"))
    s="leap year"if (year%400==0) or (year%4==0) and(year%100!=0) else "notleapyear"
    print(s)

    ردحذف
  50. #WAP to check the positive or negative value
    a=int(input("enter the value"))
    s="positive" if a>=0 or a<10==0 else "negative"
    print(s)

    ردحذف
  51. #wap to check that salary is in income tax or not display the total amount and taxtable amount
    sal = int(input("enter salary"))

    s = "not taxable" if sal<=500000 else "Tax amount is " + str(sal-500000)

    print(s)

    ردحذف
  52. #wap to check divisble by 3 and 5 or not
    a=int(input("enter the value"))
    res="divisble by 3 or 5" if a%3==0and a%5==0 else "not divisble by 3 or5"
    print(res)

    ردحذف
  53. #wap to calculate find the number is negative or positive

    x=int(input("enter value"))
    x="positive" if (x>0==0) or (x<-9==0) else "negative"
    print(x)

    ردحذف
  54. #WAP to calculate electricity bill
    up=float(input("enter unit price"))
    cons=float(input("enter consumption"))
    total=up*cons
    x="pay only 100rs" if total<400 else"actual bill is"+str(total)+"payable billis"+str(total/2)
    print(x)

    ردحذف
  55. #wap greatest two number using ternary operator:
    a=int(input("enter first number"))
    b=int(input("enter second number"))
    num="a is greatest"if a>b else "b is gratest"
    print(num)

    ردحذف
  56. #wap greatest third number using ternary operator
    a=int(input("enter first number"))
    b=int(input("enter second number"))
    c=int(input("enter thired number"))
    num="a is greatest"if a>c else "c is gratest"if c>b else "b is grearest"if a>b else "b is greatest"
    print(num)

    ردحذف
  57. #find greatest number of ?


    a=int(input("enter first number"))
    b=int(input("enter second number"))
    c=int(input("enter third number"))
    d=int(input("enter fourth number"))
    if a>b and b>c and c>d and dc and c>d and dd and d<a:
    print("c is greatest")
    else:
    print("d is greatest number")

    ردحذف
  58. #wap vowels and consonant using ternary operator
    a=input("enter vowels and consonant")
    vc="vowels"if a=='a' or a=='e'or a=='i' or a=='o'or a=='u' else "consonant"
    print(vc)

    ردحذف
  59. #wap leap year
    year=int(input("enter year"))
    s="leap year"if (year%400==0)or(year%4==0)and (year%100!=0)else"not leap year"
    print(year)

    ردحذف
  60. # wap salary .
    salary=int(input("enter salary"))
    s="not taxable"if salary<=3500000 else "tax amount"+str(salary-3500000)
    print(s)

    ردحذف
  61. # wap divisible 3 and 5
    num=int(input("enter number"))
    s="divisible by 3and5"if num%3==0 and num%5==0 else "divisible by 3" if num%3==0 else "divisible by 5" if num%5==0 else "not divisible by 3 and 5"
    print(s)

    ردحذف
  62. x=int(input("enter any number"))
    y=int(input("enter any number"))
    d="a is greater " if a>b else "b is greater"
    print(d)

    ردحذف
  63. char=input("Enter Any char")
    vc="Vowel" if char=='a' or char=='e' or char=='i' or char=='o' or char=='u' else "consonent"
    print(vc)

    ردحذف
  64. a=int(input("enter any number a"))
    b=int(input("enter any number b"))
    c=int(input("enter any number c"))
    d="a is greater" if a>b else "b is greater" if a>c else "c is greater" if b>c else "c is greater" if a<c else "c is greater"
    print(d)

    ردحذف
  65. # wap to check the greater number using ternary operator?
    a=int(input("enter first number"))
    b=int(input("enter second number"))
    c="a is greater" if a>b else "b is greater"
    print(c)

    ردحذف
  66. # wap to vowel and consonant using a ternary operator?
    vol=(input("enter the vowel and consonant="))
    x="vowel" if vol=='a' or vol=='i' or vol=='o'or vol=='e' or vol=='u' else "consonant"
    print(x)

    ردحذف
  67. # wap to check leap year using a ternary operator in python?
    year=int(input("enter the year"))
    y="leap year" if (year%400==0) or (year%4==0) and (year%100!=0) else "not leap year"
    print(y)

    ردحذف
  68. # wap to ckeck divisibility of number that it is divisible by 3 and 5
    num=int(input("enter no is divisibleor not"))
    z="divisible" if num%3==0 or num%5==0 else "not divisible"
    print(z)

    ردحذف
  69. # wap to check that salary is in income tax or not display the total amount and the taxable amount?
    salary=int(input("enter salary"))
    s="not taxable" if salary<=30000 else "taxable or taxable amount"+str(salary-30000)
    print(s)

    ردحذف
  70. # wap to calculate electricity bill where unit price,total consumption will be entered by the user,if the bill is <400 then pay only 100 rs and above this 50% amount will be paid?
    up=float(input("enter price"))
    con=float(input("enter consuption"))
    totalbill=up*con
    result="pay only 100rs" if totalbill<400 else "actual bill="+str(totalbill) + "above bill="+str(totalbill//2)
    pr

    print(result)

    ردحذف
  71. #wap to check even or odd number?
    num=int(input("enter the value"))
    s="even" if num%2==0 else "odd"
    print(s)

    ردحذف
  72. # greatest number using ternary operator?
    a=int(input("enter first number"))
    b=int(input("enter second number"))
    c=int(input("enter third number"))
    res="a is greatest" if a>c else " c is greatest" if a>b else "b is greatest" if b>c else "c is greatest"
    print(res)

    ردحذف
  73. #wap to check vowel and consonant using a ternary operator?
    ch=input ("enter vowel and consonant")
    res="vowel" if ch in ['a','e','i','o',u'] else "consonant"
    print(res)

    ردحذف
  74. a=int(input("enter number a ="))
    b=int(input("enter number b ="))
    ans="a is greater b" if a>b else "b is greater than a"
    print(ans)

    ردحذف
  75. # ternary salary amount

    sal=float(input("enter the salary amount"))
    tax=300000
    ans ="taxable" if sal>=tax else "non taxable"
    print(ans)

    ردحذف

إرسال تعليق

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