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)
#Programm for calculate the salary of the employee where basic, ta, da, comm, pf, noofleave will be entered by the user.
ReplyDelete'''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)
#reverse the five-digit number where first and last digit will be in the same position
ReplyDelete#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)
#complex number with a complex number
ReplyDeletenum1 = 2+3j
num2 = 4+5j
num = num1+num2
print(num1)
print(num2)
print(num)
#program to calculate compound interest
ReplyDelete#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)
#Program to calculate simple interest
ReplyDeletep,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)
# Python program to calculate square of a number and cube of a number
ReplyDelete# 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))
#swap two numbers without using third variable
ReplyDeletex=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)
#convert temperature from Celsius to Fahrenheit?
ReplyDelete# 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))
##perform multiplication of a complex number using complex datatype?
ReplyDeletenum1=complex(input('Enter first complex number: '))
num2=complex(input('Enter second complex number: '))
cal=num1*num2
print('"Multiplication of complex number is "', cal)
#print data in the single quote and double quote
ReplyDeleteprint("\nPrint with double quote")
print ('"Welcome in SCS"')
print("\nPrint with single quote")
print ("'Welcome in Python'")
basic = float(input("enter basic"))
ReplyDeleteta = 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)
#1a=[1,2,3,4,5]
ReplyDelete#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
Program to reverse the five-digit number where the first and last digit remains in same position--->
ReplyDeletenum=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)
Program to calculate square and cube of any entered number-->
ReplyDeletea=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)
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?
ReplyDeletename=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)
wap to calculate simple intrest
ReplyDeletep=int(input("enter principal"))
r=float(input("enter rate"))
t=int(input("enter time"))
si=float(p*r*t)/100
print("simple interst",si)
wap to revesre 5-digit number where 1st and last digit will be on same position
ReplyDeletenum=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)
wap square and cube of a number
ReplyDeletea=int(input("value of a"))
square=int(a*a)
print(square)
b=int(input("value of b"))
cube=int(b*b*b)
print(b)
wap to swap two number without using third variable
ReplyDeletea=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)
p=25000
ReplyDeleteR=2
t=2
n=12
r =R/100
A = p*((1+(r/n))**(n*t))
print(A)
Program to calculate compound interest-->
ReplyDeletep=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)
Programm to calculate the salary/ta/da/deduction of the employee where basic salary, no of leave will be entered by the user.
ReplyDeletename=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)
# PYTHON (6 to 7 PM BATCH)
ReplyDelete#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))
PARAG JAISWAL
ReplyDelete"""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)
Parag Jaiswal
ReplyDelete#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))
Parag Jaiswal
ReplyDelete#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)
Parag Jaiswal
ReplyDelete3WAP to swap two numbers without using a third variable
a = 5
b =9
a,b=b,a
print(a,b)
Parag Jaiswal
ReplyDelete#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)
Adarsh dixit
ReplyDelete'''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)
Adarsh dixit
ReplyDelete#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)
Post a Comment
If you have any doubt in programming or join online classes then you can contact us by comment .