Skip to content
Gallery
Python Fundamentals and Analytics
Share
Explore
Milestone -1

Chapter -3 : Practice Questions & Materials

Add the numbers

In Python, by default the input() function takes input in the form of a string, but what if you want to work with integers or floats? For this, you need to use data-type conversion with the input() function.
Here is a sample line of code that can be executed in Python:
# For integer Input
var1 = int(input())

# For float Input
var2 = float(input())
The above code will take the input from stdin, and store it in the var1 and var2 variables. And since we have used data-type conversion while taking the inputs the var1 contains an integer, and var2 contains a float. Try it yourself in the editor.
Task
Write a program that takes the input of two integers and prints their sum to the console.
Input Format
The first line contains a random integer
The second line contains a random integer
Output Format
Print the sum of the input values to the console.
Sample Input 1
1
2
Sample Output 1
3
Sample Input 2
15
7
Sample Output 2
22

Subtract the numbers

Task
Write a program that takes the input of two integers and subtracts the second input from the first one and prints it as the output to the console.
Input Format
The first line contains a random integer
The second line contains a random integer
Output Format
Print the subtraction of the second input from the first input to the console.
Sample Input 1
1
2
Sample Output 1
-1
Sample Input 2
15
7
Sample Output 2
8

Multiply the numbers

Task
Write a program that takes the input of two integers/floats and multiplies the first input with the second input and prints the resultant as the output to the console.
Input Format
The first line contains a random integer/float
The second line contains a random integer/float
Output Format
Print the multiplication of the first input from the second input to the console.
Sample Input 1
1
2
Sample Output 1
2
Sample Input 2
0.5
8
Sample Output 2
4

Divide the numbers

Task
Write a program that takes the input of two integers/floats and divides the first input by the second input and prints it as the output to the console.
Input Format
The first line contains a random integer/float
The second line contains a random integer/float
Output Format
Print the division of the first input by the second input to the console.
Sample Input 1
1
2
Sample Output 1
0.5
Sample Input 2
15
7
Sample Output 2
2.142857142857143

Exponential of numbers

Task
Write a program that takes the input of two integers/floats (as X and Y) and prints the as output to the console.
Input Format
The first line contains a random integer/float
The second line contains a random integer/float
Output Format
Print the exponent arithmetic resultant of the first input to the second input to the console.
Sample Input 1
1
2
Sample Output 1
1
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.