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

Assignment_Python_session6_input_eval

Uploaded by

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

Assignment_Python_session6_input_eval

Uploaded by

Shubham Chaubey
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

20/07/2024, 12:56 Python_session6_input_eval

Input

We can take the values directly in python code


ex: num=10
We can take the valu from user like from keyboard
Imagine there is application form we need to fill
In application form name: Box will appear
You need to enter your name
This is achieved by a keyword called input

In [1]: input()

Out[1]: 'Shubham'

When we type input(), a square box is appear


you need to observe
Square box
(*) Mark inside square brackets that is before cell
Python kernel is black color(means kernal is busy)
Firt fill the box with some value

In [2]: input()

Out[2]: 'Shubham'

In [3]: input()

Out[3]: 'hi'

In [4]: input()

Out[4]: 'HELLO HI HOW ARE YOU'

In [5]: input()

Out[5]: '100'

In [6]: a=10

In [7]: input()

Out[7]: 'input'

In [8]: input()

Out[8]: 'if'

*Note

file:///C:/Users/Shubham/Downloads/Python_session6_input_eval.html 1/5
20/07/2024, 12:56 Python_session6_input_eval

What ever we type in square brackets the output display in quotes


The output default type is string type

In [9]: input()
input()
input()

Out[9]: 'shubham'

In [10]: input()
input()
input()
input()
input()

Out[10]: 'Why note'

In [11]: print(input())

hello

In [15]: a=input()
print('a is = ', a)

a is = 500

In [22]: a=input()
b=input()
c= a+b
print(f'Sum of {a} and {b} is' , c)

Sum of 5 and 5 is 55

In [23]: a=input()
b=input()
c= a+b
print(c)

55

In [ ]:

In [25]: a=input()
b=input()

print(a+b)

55

In [28]: a=input()
b=input()

sum=int(a)+int(b)
print(sum)

10

In [30]: name=input()
age=input()
city=input()

file:///C:/Users/Shubham/Downloads/Python_session6_input_eval.html 2/5
20/07/2024, 12:56 Python_session6_input_eval

print(f""" My name is {name}


Iam {age} year old
and I am from {city}""")

My name is Shubham Kumar Chaubey


Iam 26 year old
and I am from Varanasi

In [31]: input()
input("Enter the Name: ")
input("Enter the Age: ")
input("Enter the City: ")

Out[31]: 'Varanasi'

In [32]: input()
input("Enter the Name:")
input("Enter the Age:")
input("Enter the City:")
input()
print(f""" My name is {name}
Iam {age} year old
and I am from {city}""")

My name is Shubham Kumar Chaubey


Iam 26 year old
and I am from Varanasi

In [34]: a=input("Enter the Number1")


b=input("Enter the Number2")
c= a+b
print(c)

4060

In [41]: a=input("Enter the Number1:")


b=input("Enter the Number2:")

sum=int(a)+int(b)
print(sum)

62

In [36]: a=int(input("Enter num1")) #workin


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

30

In [37]: a=input("Enter num1")


b=input("Enter num2")
c=int(a)+int(b) #working
print(c)

10

In [38]: a=input("Enter num1")


b=input("Enter num2")
c=int(a+b) #not working (Wrong method)
print(c)

file:///C:/Users/Shubham/Downloads/Python_session6_input_eval.html 3/5
20/07/2024, 12:56 Python_session6_input_eval

55

In [39]: a=int(input("Enter the number1: "))


b=int(input("Enter the number2: "))
a+b

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[39], line 2
1 a=int(input("Enter the number1: "))
----> 2 b=int(input("Enter the number2: "))
3 a+b

ValueError: invalid literal for int() with base 10: '200.25'

In [ ]: a=int(input("Enter the number1: "))


b=int(input("Enter the number2: "))
a+b

Eval

Whenever you listen eval: evalute


evalute is belong to math family
It will convert integer value to integer
it will convert Float to the vloat only
Directly apply the eval and it will convert into corresponding data type,Whenever
you use eval, dont provide String it will give the error

In [44]: a=eval(input("Enter the number1: "))


b=eval(input("Enter the number2: "))
a+b

Out[44]: 30.5

In [47]: a=eval(input("Enter the number1: "))


b=eval(input("Enter the number2: "))
print(a+b)

3.5

In [48]: a=eval(input("Enter the number1: "))


b=eval(input("Enter the number2: "))
print(round(a+b))

58

In [49]: #Qut01

a=eval(input("Give 1st number: "))


b=eval(input("Give 2nd number: "))
c=eval(input("Give 3rd number: "))
avg=(a+b+c)/3

print(round(avg))

41.333333333333336

file:///C:/Users/Shubham/Downloads/Python_session6_input_eval.html 4/5
20/07/2024, 12:56 Python_session6_input_eval

In [51]: #Qut02

Hight= eval(input("Hight: "))#hight


Bredth=eval(input("Bredth: ")) #Bredth
area=round(1/2*Hight*Bredth)
print(round(area))

1000

In [52]: #Qut03

Hight= eval(input("Hight: "))#hight


Length=eval(input("Length: ")) #Length
area= Length*Hight

print(area)

600

In [54]: #Qut04

redius = eval(input("Redius is: "))


pie= 3.14

area= pie*redius*redius

print(area)

78.5

In [57]: #Qut05

Billamount=eval(input("Bill is: "))


Tip=eval(input("% Tip is: "))
Per=Billamount*Tip/100
TotalAmount= Per+Billamount #Total bill

print(f"TotalAmount is {TotalAmount}: ")

TotalAmount is 5050.0:

In [ ]:

file:///C:/Users/Shubham/Downloads/Python_session6_input_eval.html 5/5

You might also like