Now, you know how to print something on a screen. So, let's learn how to take input from the user.

- Python 2
- Python 3

```
name = input("What is your name >>>")
```

- Python 2
- Python 3

```
print("Enter your name")
x = input()
y = input("age >>>") #age>>> will be printed before input
print("Your name is",x,"and","and your age is",y)
```

`'input()'`

is used to take input from the user. We can also write something inside `input()`

to make it appear before the input, as done in the previous example, `input("age >>>")`

.

Let's see some examples.

- Python 2
- Python 3

```
print("Enter your wish")
wish = input()
print("May your wish come true!")
```

Anything given to `input`

is returned as a string. So, if we give an integer like 5, we will get a string i.e. ** '5' (a string)** and

**not**.

`5`

(int)Now, let's learn to take integer input from the user.

- Python 2
- Python 3

```
x = int(input("Enter an integer >>>"))
print ("You have entered",x)
```

You have entered 12

`int`

changes a string to an integer. For example, `int('12')`

will give us an integer 12.

In the above example, we are taking the input from the user as a string with the `input()`

and then we are using the `int()`

to change it to an integer. So, if a user will enter 10, then the `input()`

will become '10' (a string) and the above statement `int(input())`

will become `int('10')`

and we will get 10 as an integer.

We can also break the above example in one more step to understand better.

```
x = input("Enter an integer >>>")
y = int(x)
print("You have entered",y)
```

You have entered 12

Here, we passed 12. Thus, `x`

became `'12'`

and then `int(x)`

turned it into an integer.

### What does input() do?

- Python 2
- Python 3

```
x = input(">>>")
print(x)
```

This code is similar to `x = '10'`

.

We gave 10 to the `input()`

. You can think that `input()`

becomes 10. So, `x = input()`

will be similar to `x = 10`

after the input is given.

### How to take float (decimals)?

Similar to taking input of integers, we can use `float()`

to take an input from the user and change it to a float.

- Python 2
- Python 3

```
x = float(input())
print(x)
print(type(x))
```

It is similar to taking input of integers. We entered 12.32 to `input()`

which will return `'12.32'`

(a string). Thus, the expression `float(input())`

will become `float('12.32')`

. And this will give us a float `12.32`

.

Now, let's try this.

- Python 2
- Python 3

```
print(int(7.4))
```

This is **type conversion**. 7.4 is a float (decimal). So by writing **int(7.4)**, we are converting it into an integer and thus, it got converted to 7.

This is very useful in some situations, where you want to convert a variable in the middle of your program.

So, in the initial examples of this chapter, we used `int()`

to convert strings (the inputs we were taking were strings) into integers and then converted floats into integers. Let's proceed ahead and learn some mathematical functions available in Python.

## Let your computer do some maths for you.

- Python 2
- Python 3

```
import math
print(math.sin(30))
print(math.cos(10))
print(math.pow(2,3))
```

`import math`

→ This will include Python's inbuilt directory 'math'. It contains many mathematical functions for our use. `import`

is a keyword used to import any available directory.

`math.sin()`

computes sine of a given angle.

`math.cos()`

computes cosine of a given angle.

`math.pow(a,b)`

computes a raised to the power of b (a^{b}).

We have imported 'math' and these functions are inside it, so 'math.sin()' can be understood as 'sin()' from 'math' directory.

Checkout python's official documentation for more functions available in math.