TutorMe homepage
Start Free Trial
Ajeet Kumar S.
Application Developer at IBM
Tutor Satisfaction Guarantee
Python Programming

How to input multiple values from the user in one line in Python?

Ajeet Kumar S.

For instance, in C we can do something like this: // Reads two values in one line scanf("%d %d", &x, &y) One solution is to use raw_input() two times. x, y = raw_input(), raw_input() But in Python 3, raw_input() method deprecated . And for input input() used. Another solution is to use split() x, y = raw_input().split() Note that we don’t have to explicitly specify split(‘ ‘) because split() uses any whitespace characters as delimiter as default. One thing to note in above Python code is, both x and y would be of string. We can convert them to int using another line x, y = [int(x), int(y)] # We can also use list comprehension x, y = [int(x) for x in [x, y]] Below is complete one line code to read two integer variables from standard input using split and list comprehension # Reads two numbers from input and typecasts them to int using # list comprehension x, y = [int(x) for x in raw_input().split()] Note that in Python 3, we use input() in place of raw_input().

Basic Math

1. In the first 10 overs of a cricket game, the run rate was only 3.2. What should be the run rate in the remaining 40 overs to reach the target of 282 runs?

Ajeet Kumar S.

Runs scored in the first 10 overs = 10 × 3.2 = 32 Total runs = 282 Remaining runs to be scored = 282 - 32 = 250 Remaining overs = 40 Run rate needed = 250 40 = 6.25

C++ Programming

1. What are virtual functions?

Ajeet Kumar S.

Virtual functions are used with inheritance, they are called according to the type of the object pointed or referred, not according to the type of pointer or reference. In other words, virtual functions are resolved late, at runtime. Virtual keyword is used to make a function virtual. Following things are necessary to write a C++ program with runtime polymorphism (use of virtual functions)
1) A base class and a derived class.
2) A function with the same name in base class and derived class.
3) A pointer or reference of base class type pointing or referring to an object of derived class. For example, in the following program, bp is a pointer of type Base, but a call to bp->show() calls show() function of the Derived class because bp points to an object of the Derived class. #include<iostream> using namespace std; class Base { public: virtual void show() { cout<<" In Base \n"; } }; class Derived: public Base { public: void show() { cout<<"In Derived \n"; } }; int main(void) { Base *bp = new Derived; bp->show(); // RUN-TIME POLYMORPHISM return 0; } OUTPUT = >In Derived

Send a message explaining your
needs and Ajeet Kumar will reply soon.
Contact Ajeet Kumar
Ready now? Request a lesson.
Start Session
What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Session" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.