

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to read input from console
Suppose we have to take firstname and lastname from console and write a prompt like "Hello <firstname> <lastname>, you are welcome!". To get the result we can use the format() class.We can placeholder into the string using {}, then pass arguments into format() function.
So, if the input is like Ashish Dutta, then the output will be "Hello Ashish Dutta, you are welcome!"
To solve this, we will follow these steps −
fn := take first input from the console
ln := take second input from the console
ret := "Hello a {} {}, you are welcome!" then call format with this string like format(fn, ln)
return ret
Example
Let us see the following implementation to get better understanding
def solve(): fn = input() ln = input() ret = "Hello {} {}, you are welcome!".format(fn, ln) return ret print(solve())
Input
Ashish Dutta
Output
Hello Ashish Dutta, you are welcome!
- Related Questions & Answers
- Way to read input from console in C#
- Ways to read input from console in Java
- Taking input from console in Python
- Read integers from console in Java
- Java Program to Read The Number From Standard Input
- How to read a line from the console in C#?
- How to read data from user using the Console class in Java?
- Java Program to read the next byte of data from the input stream
- How to read data from PDF file and display on console in Java?
- How can we read from standard input in Java?
- Get number from user input and display in console with JavaScript
- Java program to read numbers from users
- Can we read from JOptionPane by requesting input from user in Java?
- Java Program to get text from JTextPane and display in Console
- Write a program in Python to read sample data from an SQL Database
Advertisements