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

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

Input and Output Operation in Python, How to take input from the user's in Python, How to display output in Python


Python provides a predefined function to take input from the keyboard and display output into the monitor.


1)  input():-  

It is used to take input from the keyboard using a String pattern (a combination of char), we can pass the display message as a parameter into input(). that is used to reduce the extra code as compared to C and CPP programming language.


var = input("message") 
   #var is the variable name which will assign input data into string pattern

we can convert input data into another datatype such as int, float using the type conversion method.


int():-   It is used to convert numeric String type data or float type data to an integer.

Syntax:-


var  = int(input("message")) 
 #it will take integer type input


int() is used to convert numeric string type data to the integer type.


Float():- float() is used to convert numeric string type data to float type.

Syntax:-

var = float(input("message"))  #it will take input for float type


Str():-  It is used to convert integer type data to String type, but no need to use it under input() because of the Input method linked with str() by default.



2)  print():-    

It is used to display output data using a single statement and multiple statements.

print("statement1")     #Single Statement

print("statement1","statement2")  #Multiple Statements

print("statement1"+"statement2")  #Concatenation with two Strings

print("statement1" + str(10))  #str() is used to convert int ,float to String 

print("result is ",12.3444567891)  #print float value

print("result is %.2f" %  12.3444567891) #print formatted float value

print("{0},{1}".format(2,3))  # {0} and {1} is called placeholder in print()



A basic example of str() in:-

s="hello"
y=10
print(s+str(y))
a=10
b=20.34
print(a+b)

Program assignment:-


  1. WAP to calculate the salary of the employee where basic, ta, da, comm, pf, noofleave will be entered by the user?
  2. WAP to calculate compound interest?    *
  3. WAP to reverse the five-digit number where the first and last digit will be in the same position
  4. WAP to swap two numbers without using a third variable
  5. WAP to calculate square and cube of any entered number?






40 Comments

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

  1. #Programm for calculate the salary of the employee where basic, ta, da, comm, pf, noofleave will be entered by the user.

    '''Get Basic Salary of Employee,
    DA = 25% of Basic,
    HRA = 15% of Basic,
    PF = 12% of Basic,
    TA = 7.50% of Basic,
    Net Pay = Basic + DA + HRA + TA,
    Gross Pay = Net Pay - PF. '''

    name=str(input("Enter the name of employee: "))
    basic=float(input("Enter the basic salary: "))
    da=float(basic*25)/100
    hra=float(basic*15)/100
    pf=float(basic*12)/100
    ta=float(basic*7.50)/100
    netpay=float(basic+da+hra+ta)
    grosspay=float(netpay-pf)

    print("\n\n")
    print("Salary Detail")
    print("\n")

    print(" NAME OF EMPLOYEE : ",name)
    print(" BASIC SALARY : ",basic)
    print(" DEARNESS ALLOW. : ",da)
    print(" HOUSE RENT ALLOW.: ",hra)
    print(" TRAVEL ALLOW. : ",ta)
    print("\n")
    print(" NET SALARY PAY : ",netpay)
    print(" PROVIDENT FUND : ",pf)
    print(" GROSS PAYMENT : ",grosspay)


    ReplyDelete
  2. #reverse the five-digit number where first and last digit will be in the same position
    #Reverse Program Answer?
    num=12345
    print("Actual number is",num)
    a=num%10 #5
    num=num//10 #1234
    b=num%10 #4
    num=num//10 #123
    c=num%10 #3
    num=num//10 #12
    d=num%10 #2
    e=num//10 #1
    num1= e*10000+b*1000+c*100+d*10+a*1
    print("Reverse of number is",num1)

    ReplyDelete
  3. #complex number with a complex number
    num1 = 2+3j
    num2 = 4+5j
    num = num1+num2
    print(num1)
    print(num2)
    print(num)

    ReplyDelete
  4. #program to calculate compound interest
    #formula : p * (pow((1 + r / 100), t))

    p=float(input("Enter the principal amount :"))
    t=float(input("Enter the number of year :"))
    r=float(input("Enter the rate of intrest :"))

    #compund interest
    ci=p*(pow((1+r/100),t))

    print("Compound Interest %.2f" % ci)

    ReplyDelete
  5. #Program to calculate simple interest

    p,r,t=12000,2.2,3.5
    si=(p*r*t)/100
    print("result is p={0} , r={1} , t={2} ,si={3} ".format(p,r,t,si))
    #print("result is %.2f" % si)

    ReplyDelete
  6. # Python program to calculate square of a number and cube of a number
    # Method 3 (using math.pow () method)

    # importing math library
    import math

    # input a number
    number = int (input ("Enter an integer number: "))

    # calculate square
    square = int(math.pow (number, 2))
    cube = int (math.pow (number, 3))

    # print
    print ("Square of {0} is {1} ".format (number, square))
    print ("Cube of {0} is {1} ".format (number, cube))

    ReplyDelete
  7. #swap two numbers without using third variable
    x=int(input("Enter the value of X : "))
    y=int(input("Enter the value of Y : "))

    print ("Before swapping: ")
    print("Value of X : ", x, " and Y : ", y)

    # code to swap 'x' and 'y'
    x, y = y, x

    print ("After swapping: ")
    print("Value of x : ", x, " and y : ", y)

    ReplyDelete
  8. #convert temperature from Celsius to Fahrenheit?
    # formula --> fahrenheit = (celsius * 1.8) + 32

    celsius=float(input(" Temperature in Celsius : "))
    fahrenheit=(celsius*1.8)+32
    print("{0} degree Celsius is equal to {1} degree Fahrenheit".format (celsius,fahrenheit))

    ReplyDelete
  9. ##perform multiplication of a complex number using complex datatype?
    num1=complex(input('Enter first complex number: '))
    num2=complex(input('Enter second complex number: '))
    cal=num1*num2
    print('"Multiplication of complex number is "', cal)

    ReplyDelete
  10. #print data in the single quote and double quote

    print("\nPrint with double quote")

    print ('"Welcome in SCS"')

    print("\nPrint with single quote")
    print ("'Welcome in Python'")

    ReplyDelete
  11. basic = float(input("enter basic"))
    ta = float(input("enter ta"))
    da = float(input("enter da"))
    comm = float(input("enter commision"))
    pf = float(input("enter pf "))
    nl = float(input("enter number of leave"))
    tsal = basic+ta+da+comm
    deduction = ((tsal)/30) *nl
    gsal = tsal-deduction-pf
    print("CTC",tsal)
    print("Gross salary",gsal)
    print("Total pf ",pf," Leave deduction is ",nl)

    ReplyDelete
  12. #1a=[1,2,3,4,5]
    #1print(a[::-1])
    #2num1=2+3j
    #2num2=3+4j
    #2num=num1+num2
    #2print(num)
    ##num2=5+4j
    #a=2+5
    #b=(3+4)

    #a=12345%10
    #num=12345//10
    #b=1234%10
    #num=1234//10
    #c=123%10
    #num=123//10
    #d=12%10
    #num=12//10
    #e=1
    #num=a*10000+b*1000+c*100+d*10+e
    #print(num)
    #num=12345

    ReplyDelete
  13. Program to reverse the five-digit number where the first and last digit remains in same position--->

    num=12345
    a=num%10
    num=num//10
    b=num%10
    num=num//10
    c=num%10
    num=num//10
    d=num%10
    e=num//10
    rev=a*1+d*10+c*100+b*1000+e*10000
    print("rev of a number",rev)

    ReplyDelete
  14. Program to calculate square and cube of any entered number-->

    a=input("enter the value of a")
    square=int(a)*int(a)
    print("square of a=",square)
    cube=int(a)*int(a)*int(a)
    print(cube of a=",cube)

    ReplyDelete
  15. WAP to calculate the salary of the employee where basic, ta, da, comm, pf, noofleave will be entered by the user?WAP to calculate the salary of the employee where basic, ta, da, comm, pf, noofleave will be entered by the user?
    name=str("enter the employee name")
    basic=float(input("enter salary"))
    da=float(basic*10)/100
    hra=float(basic*25)
    pf=float(basic*5)
    ta=float(basic*6.5)
    netpay=float(basic+da+hra+ta)
    grosspay=float(netpay-pf)
    print("\n\n")
    print("name of employee",name)
    print("basic salary",basic)
    print("dear allowness",da)
    print("hra",hra)
    print("provident fund",pf)
    print("travell allowness",ta)
    print("\n")
    print("netpay",netpay)
    print("providentfund",pf)
    print("gross salary",grosspay)

    ReplyDelete
  16. wap to calculate simple intrest
    p=int(input("enter principal"))
    r=float(input("enter rate"))
    t=int(input("enter time"))
    si=float(p*r*t)/100
    print("simple interst",si)

    ReplyDelete
  17. wap to revesre 5-digit number where 1st and last digit will be on same position
    num=int(input("enter 5-digit number")
    a=num%10
    num=num//10
    b=num%10
    num=num//10
    c=num%10
    num=num//10
    d=num%10
    e=num//10
    num1=e*10000+d*1000+c*100+b*10+a*1
    print(nim1)

    ReplyDelete
  18. wap square and cube of a number
    a=int(input("value of a"))
    square=int(a*a)
    print(square)

    b=int(input("value of b"))
    cube=int(b*b*b)
    print(b)

    ReplyDelete
  19. wap to swap two number without using third variable
    a=int(input("value of a"))
    b=int(input("value of b"))
    print("before swap")
    a,b=b,a
    print("after swap")
    print("a=",a,"b=",b)

    ReplyDelete
  20. p=25000
    R=2
    t=2
    n=12
    r =R/100
    A = p*((1+(r/n))**(n*t))
    print(A)

    ReplyDelete
  21. Program to calculate compound interest-->
    p=int(input("enter the value of p"))
    R=int(input("enter the value of R"))
    t=int(input("enter the value of t"))
    n=int(input("enter the value of n"))
    r=R/100
    ci=p*((1+(r/n))**(n*t)-1)
    print(ci)

    ReplyDelete
  22. Programm to calculate the salary/ta/da/deduction of the employee where basic salary, no of leave will be entered by the user.

    name=str(input("enter name of employee"))
    basic = float(input("enter basic salary"))
    ta = float(basic*5)//100
    da = float(basic*6)//100
    comm = float(basic*3)//100
    pf = float(basic*12)//100
    nl = float(input("enter number of leave"))
    sal = basic+ta+da+comm
    deduct = ((sal)//30) *nl
    gsal = sal-deduct-pf
    print("CTC",sal)
    print("Gross salary",gsal)
    print("Total pf ",pf," Leave deduction= ",deduct)

    ReplyDelete
  23. # PYTHON (6 to 7 PM BATCH)
    #Program for swaping two numbers without using a third variable
    a = int(input("Enter The Value for A :\t"))
    b = int(input("Enter The Value for B :\t"))
    print("Value of A:\t",a,":\n""Value of B:\t",b)
    print("After swaping two numbers:\tA={0}\tB={1}".format(b,a))


    ReplyDelete
  24. PARAG JAISWAL
    """WAP to calculate the salary of the employee where basic, ta, da, comm, pf, noofleave will be entered by the user?"""
    basic_salary = int(input("Enter your basic salary = "))
    ta = int(input("Enter your ta = "))
    da = int(input("Enter your da = "))
    comm = int(input("Enter your comm = "))
    pf = int(input("Enter your pf amount = "))
    no_of_leave = int(input("Enter your no. leave = "))

    leave_amount = no_of_leave * ((basic_salary + ta + da +comm +pf)/30)
    net_salary =basic_salary + ta + da + comm + pf - leave_amount
    print("Your net salary = ",net_salary)


    ReplyDelete
  25. Parag Jaiswal
    #WAP to calculate compound interest?

    p = int(input("Enter principal amount = "))
    r = int(input("Enter rate of interest = "))
    t = int(input("Enter time period = "))

    total_value = p * ((1 + (r/100)) ** t)

    print("Total Amount = %.2f"%total_value)
    print("Compund Interest = %.2f"% (total_value - p))

    ReplyDelete
  26. Parag Jaiswal
    #WAP to reverse the five-digit number where the first and last digit will be in the same position

    num =12345
    e =num % 10 #1
    num = num // 10 # 5432
    b = num % 10 #2
    num = num // 10 #543
    c = num % 10 #3
    num = num // 10 #54
    d = num % 10 # 4
    a = num //10 # 5
    rev = a * 10000 + b * 1000 + c * 100 + d * 10 + e * 1
    print (rev)

    ReplyDelete
  27. Parag Jaiswal
    3WAP to swap two numbers without using a third variable
    a = 5
    b =9

    a,b=b,a

    print(a,b)

    ReplyDelete
  28. Parag Jaiswal
    #WAP to calculate square and cube of any entered number?
    num =int(input("Enter number = "))
    square = pow(num , 2)
    cube = num ** 3
    print("Square and cube of ", num, "is", square ,"&",cube)

    ReplyDelete
  29. Adarsh dixit
    '''WAP to calculate the total salary of an employee where basic, ta, da, comm, pf,hra, leave will be entered by the users?'''
    basic_salary = int(input("enter ur basic salary: "))
    ta = int(input("enter ur ta: "))
    da = int(input("enter ur da: "))
    comm = int(input("enter ur comm: "))
    pf = int(input("enter ur pf amount: "))
    num_of_leave = int(input("enter ur num of leave: "))

    leave_amount = num_of_leave*((basic_salary+ta+da+comm+pf)/30)
    net_salary =basic_salary + ta + da + comm + pf - leave_amount
    print("ur net salary=",net_salary)

    ReplyDelete
  30. Adarsh dixit
    #WAP to swap two numbers without using a third variable

    a = 5
    b = 6

    print("before swaping: ")
    print("value of a : ",a,"value of b : ",b)

    a,b = b,a

    print("after swaping")
    print("value of a : ",a,"value of b : ",b)

    ReplyDelete
  31. To calculate compound interest:-
    (p,r,n,t)=(12000,4.3,3,2)
    print(p)
    print(r)
    print(n)
    print(t)
    A=p*(1+(r/n))**(n*t)
    print(A)

    ReplyDelete
  32. reversed the five-digit number where the first and last digit will be in the same position:-
    x=12345
    print("Given Number:", x)
    a=x%10
    x=x//10
    b=x%10
    x=x//10
    c=x%10
    x=x//10
    d=x%10
    e=x//10
    y=e*10000+b*1000+c*100+d*10+a*1
    print("Reverse of the middle part of the given number:", y)

    ReplyDelete
  33. #MOhit Chouhan
    1.
    empsal=int(input("Enter the salary : " ))
    ta=int(input("Enter the TA : " ))
    da=int(input("Enter the DA : " ))
    comm=int(input("Enter the comm : " ))
    pf=int(input("Enter the pf : "))
    lea=int(input("Enter the leave : "))

    total=(empsal+ta+da+comm-pf)
    print("salary before leave : ", total)
    b=empsal/30
    w=b*lea

    final=(total-w)
    print("Final salary : ", final)

    2.
    p=int(input("Enter the principal:"))
    r=int(input("Enter the Rate: "))
    t=int(input("Enter the Time : "))

    ci= (p*(1+(r/100))**t)

    print("your compunt intrest is : " ,ci-p)

    3.
    a=int(input("Enter the five digit number : ")) #12345
    r=a%10 #5
    b=a//10 #1234
    s=b%10 #4
    c=b//10 #123
    t=c%10 #3
    d=c//10 #12
    u=d%10 #2
    e=d//10 #1
    print((str(e)+str(s)+str(t)+str(u)+str(r)))

    4.
    a=int(input("Enter the 1st Value plz: "))
    b=int(input("Enter the 2nd Value plz : "))

    print("Before swapping : ", a ,b )
    a,b=b,a
    print("after swapping : ", a ,b)

    5.
    a=int(input("Enter the value : "))
    v= a*a
    print("The Squre of your value is : ", v)
    w= a*a*a
    print("The cube of your value is : ", w)




    ReplyDelete
  34. # WAP to calculate the total salary of an employee where basic, ta, da, comm, pf,hra, leave will be entered by the users?

    '''basic:- 12000
    ta= 400
    da=200
    comm=500
    pf =-500
    hra = 300
    leave=3'''

    ta=int(input("enter ta : "))
    da=int(input("enter da : "))
    comm=int(input("enter comm : "))
    pf=int(input("enter pf : "))
    hra=int(input("enter hra : "))
    sal=int(input("enter basic salary : "))
    lve=int(input("enter leave's : "))

    c=(ta+da+comm+hra-pf)
    onedy=sal/30
    tslry=((30-lve)*onedy)
    final=tslry+c;
    print("actual salary=",final)

    ReplyDelete
  35. #WAP to calculate compound interest?

    p=int(input("put p : "))
    r=float(input("put r : "))
    t=float(input("put t : "))

    ci=p*(pow((1+r/100),t));
    print("%.2f"%ci)

    ReplyDelete
  36. n=int(input("Enter the 5'digites number : "))
    a=n%10 #5
    n=n//10 #1234
    b=n%10 #4
    n=n//10 #123
    c=n%10 #3
    n=n//10 #12
    d=n%10 #2
    n=n//10 #1
    e=n%10 #1
    n=n//10 #0
    z=( ( ( ( ( ( ( (e*10)+b)*10)+c)*10)+d)*10)+a)
    print(z)

    ReplyDelete
  37. # WAP to swap two numbers without using a third variable (two ways foe without using third variable in python)

    '''a,b=int(input("a:")),int(input("b:"))
    a,b=b,a
    print("a:",a,"b:",b)'''


    a,b=int(input("a:")),int(input("b:"))
    a=a+b
    b=a-b
    a=a-b
    print("a:",a,"b:",b)

    ReplyDelete
  38. # WAP to swap two numbers without using a third variable (two ways foe without using third variable in python)

    '''a,b=int(input("a:")),int(input("b:"))
    a,b=b,a
    print("a:",a,"b:",b)'''


    a,b=int(input("a:")),int(input("b:"))
    a=a+b
    b=a-b
    a=a-b
    print("a:",a,"b:",b)

    ReplyDelete
  39. #WAP to calculate square and cube of any entered number?

    no=int(input("Enter a number : "))
    square=
    cube=no*no*no
    square=pow(no,2) # no*no;
    cube=pow(no,3) # no*no*no; square*no;
    print("Square is",square)
    print("Cube is",cube)

    ReplyDelete
  40. WAP to reverse a five-digit number without using a loop?
    num=12345
    print(num)
    a=num%10
    num=num//10
    b=num%10
    num=num//10
    c=num%10
    num=num//10
    d=num%10
    e=num//10
    num1=a*10000+b*1000+c*100+d*10+e*1
    print(num1)

    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