Uncategorized

python input and output function in hindi by unitdiploma

45views

Input Function

•To accept input from keyboard, Python provides the input() function. This function takes a value from the keyboard and returns it as a string.

Example:

  str=input(‘enter you city: ‘)

  print(str)

  str=input(‘enter a number: ‘)

  x=int(str)

  print(x)

  x=int(input(‘enter any no.: ‘))

  print(x)

  x=float(input(‘enter any no.: ‘))

  print(x)

Output:
enter you city: gorakhpur
gorakhpur
enter a number: 4
4
enter any no.: 54
54
enter any no.: 37.5
37.5
 

Output Function

print() function is used to output data to the standard output device (screen).

  print(‘This sentence is output to the screen’)

          # Output: This sentence is output to the screen

  a = 5

  print(‘The value of a is’, a)

    # Output: The value of a is 5

Examples of Output Function

print(‘hello’)

print(‘hello \tPython’)

print(‘hello ‘*3)

print(‘hello’+’Python’)

a,b=2,4

print(a)

print(a,b)

print(a,b,sep=”,”)

print(a,b,sep=”:”)

print(a,b,sep=”____”)

print(“hello”)

print(“welcome”,end=””)

print(“python”)

print(1,2,3,sep=”,”,end=”&”)

Examples of Output Function

a,b,c=24,25,27

print(‘num1={}’.format(a))

a,b,c=10,20,30

print(‘num1={},num2={},num3={}’.format(a,b,c))

print(‘num1={0},num2={1},num3={2}’.format(a,b,c))

print(‘num1={2},num2={1},num3={0}’.format(a,b,c))

name,sal=’amit’,35200.00

print(‘Hi {0}, your salary is {1}’.format(name,sal))

print(‘Hi {x}, your salary is {s}’.format(x=name,s=sal))

Program to sum of two numbers

  a = int(input(“enter first number: “))

  b = int(input(“enter second number: “)) 

  sum= a + b

   print(“Sum of two numbers is:”, sum)

Problems

•The length & breadth of a rectangle and radius of a circle are input through the keyboard.

•Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.

•Employee’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.

•If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.

•The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.

•Two numbers are input through the keyboard into two locations a and b. Write a program to interchange the contents of a and b.

Leave a Response