Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Accepting input from console:

Here we basically study about shell…..

console(also called shell) is basically a command line interpreter that takes input from the user i.e.
execute one command at a time . line by line and then translate and show the result.

If our command is error free then it runs the command and gives a required output, otherwise
shows the error message.

The primary prompt of the python console is the three greater than symbols >>>(i.e. in python idle,
you can see these symbols, by using this, you can perform all your primary task.)

Accepting input from console by input():

Gernally users enters the values in the console and according to the values, you can get an output

-To take input from the user we use the built-in-function input().

Input()

Input() function can be used to read data(i.e. entered data) directly from the keyboard, that data
must be in string type.

We have to convert that string type to our required type(i.e. it must be int, float etc), by using type
casting method we can convert our entered data in integer type or float type.

How the input() function works in python:


When input() function executes program flow will be stopped (like: it will stop the flow of your
execution for the input ( i.e. to take the value from the user)

>>Whatever user enter as input, input function convert it into a string.

>>If user enter an integer value still input() function convert it into a string.

>> by using typecasting method it will show us that value in integer or float type….(i.e. here we use
explicit typecasting.

Example:

a=input() #here we enter any kind of value

34

>>> print(a)

34

>>> type(a)
<class 'str'> #as you see its you can enter any type of value it will take this is an string type

>>> b=int(a) #now here we can take a variable and then do explicit typecasting

>>> print(b)

34

>>> type(b)

<class 'int'>

Example2 :
#program to calculate the interest.
#for interest, we have a principle amount(p), time period(t) and rate(r)
p=float(input(“Principle amount:”))
t=float(input(“Time period:”))
r=float(input(“Rate of intrest:”))
si=(p*t*r)/100 #formula for calculating interest
#for total amount we can take total variable and add principle amount to
interest
total=p+si #total amount
#to create a difference between two paragraph, we can print a simple line by
using (#,****)
print(“*#” * 30)
print(“interest of amount=”,si)
print(“total amount=”, total)
Printing statements:
Print()
The print() function prints or show the given object to the screen.
The print function is called a built-in-function because it is part of the python
standard functions library.
You don’t need to do anything special to get this function.
When you install python, you automatically is able to use that function.

Syntax:
print(*objects, sep=’ ‘, end=’\n’, file=sys.stdout, flush=false)
objects: objects to the printed(i.e. you can show any kind of data on your
ouptut screen)
sep: “ string “, data (i.e. here for display the output of given data, the data is
written like this in print function)
end: (\n) is used to take your pointer to next line.
sys.stdout: used to prints the objects (data) on the screen.
Flush: provide you the result in true of false.

You might also like