0% found this document useful (0 votes)
101 views

Print, Input - Jupyter Notebook

The print() function prints output to the screen or other output device. It takes object(s) as parameters and has optional parameters like separator, end, file, and flush. The input() function allows user input and returns it as a string. A program example takes two numbers as input from the user and prints their sum. Another example calculates simple interest given principal amount, rate of interest, and time as user input. The eval() method parses and runs Python expressions passed to it within a program.

Uploaded by

Shivam Motla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

Print, Input - Jupyter Notebook

The print() function prints output to the screen or other output device. It takes object(s) as parameters and has optional parameters like separator, end, file, and flush. The input() function allows user input and returns it as a string. A program example takes two numbers as input from the user and prints their sum. Another example calculates simple interest given principal amount, rate of interest, and time as user input. The eval() method parses and runs Python expressions passed to it within a program.

Uploaded by

Shivam Motla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Output with Print an Formatted Output

The print() function prints the specified message to the screen,


or other standard output device.
#Syntax

print ( object(s) , separator=separator, end=end, file=file, flush=flush)

Parameter Description

object(s) Any object, and as many as you like. Will be converted to string before printed

sep='separator' Optional. Specify how to separate the objects, if there is more than one. Default is ''

end='end' Optional. Specify what to print at the end. Default is '\n' (line feed)

file Optional. An object with a write method. Default is sys.stdout

flush Optional. A Boolean, specifying if the output is flushed (True) or buffered (False). Default is False

In [2]: a,b=10,30
print(a,b)

10 30

In [3]: print(a,b,sep="\n")

10
30

In [8]: # End
print(a,end="rs.")
print(b)

10rs.30

In [ ]:

Python input() Function


The input() function allows user input. Syntax input(prompt)

In [9]: # Input function return every value as a string

n = input("Enter any int value")


print(type(n))

Enter any int value123


<class 'str'>

In [13]: # write a program which takes two number from user and display sum of it

a = input("Enter first number")


b = input("Enter Second Number")
c = int(a)+int(b)
print(c)

Enter first number10


Enter Second Number20
30
In [14]: # or

a = int(input("Enter first number"))


b = int(input("Enter Second Number"))
c = a+b
print(c)

Enter first number123


Enter Second Number2
125

In [9]: # Write a program to calculate SI (SI = Principle Amount * Rate of Interest * Time /100)
p = float(input("Enter Principle Amount"))
r = float(input("Enter Rate of Interest"))
t = float(input("Enter time"))
# Expression
si = (p*r*t)/100
print("Simple Interest of principle amount = {},rate of interest = {},time = {} will be {}".format(p,r,
#print(f"Simple Interest of principle amount = {p},rate of interest = {r},time = {t} will be {si}")

Enter Principle Amount1250.5


Enter Rate of Interest8.5
Enter time1.5
Simple Interest of principle amount = 1250.5,rate of interest = 8.5,time = 1.5 will be 159.43875

eval in Python
The eval() method parses the expression passed to it and runs python expression(code) within the program.

In [ ]:

In [ ]:

In [ ]:

Example
In [ ]:

You might also like