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

Chapter -2 : Practice Questions & Materials

Print statement

In Python, the print() function prints the specified message to the screen or other standard output device.
Here is a sample line of code that can be executed in Python:
print("Hello, World!")
The above code will print Hello, World! on your screen. Try it yourself in the editor.
Task
Print Hello, World! to the console.
Input Format
You do not need to read any input in this challenge.
Output Format
Print Hello, World! to stdout.
Sample Input 1
Sample Output 1
Hello, World!

Define a variable

In Python, the input() function takes the input from stdin and passes the input to a variable.
Here is a sample line of code that can be executed in Python:
var = input()
The above code will take the input from stdin, and store it in the "var" variable. Try it yourself in the editor.
Task
Define a variable "age" by taking input of a number from stdin, and printing it as an output to the console.
Input Format
You need to read a random number as input in this challenge.
Output Format
Print the input number to stdout
Sample Input 1
100
Sample Output 1
100
Sample Input 2
-1
Sample Output 2
-1

Define multiple variables at once.

The input() function only accepts a single line input, but what if you want to take input of multiple values and they are in different lines? For this, you use multiple input() functions to read all those inputs.
Here is a sample line of code that can be executed in Python:
var1 = input()
var2 = input()
var3 = input()
The above code will read 3 lines of input and store them in var1, var2, and var3 respectively. Try it yourself in the editor.
Task
Define 3 variables as "name", "age", and "gender" and print them to the console.
Input Format
The first line will be a random name
The second line will be a random number
The third line will be either Male or Female
Output Format
Print the values of all three variables to stdout, in a single line.
Sample Input 1
Ram
45
Male
Sample Output 1
Ram 45 Male
Sample Input 2
Jaya
21
Female
Sample Output 2
Jaya 21 Female

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.