Data Input: input() function

Theory

The example above is inconvenient because the source data for the program is specified in the program text, and in order to use the program for another triangle, it is necessary to correct the program text. This is inconvenient; it is better that the program text does not change, and the program asks the user for the data necessary to solve the problem, that is, it asks for the values ​​of two initial variables a and b. To do this, we will use the function input(), which reads a line from the keyboard and returns the value of the read line, which we will immediately assign to the variables a and b:

a = input()
b = input()

True, the function input returns a text string, but we need to make sure that the variables have integer values. Therefore, immediately after reading, we will perform a type conversion using the function int, and write the new values ​​to the variables a and b.

a = int(a)
b = int(b)

You can combine string reading and type conversion by calling the function int on the value that the function returns input:

a = int(input())
b = int(input())

Next in the program we will calculate the value of the variable c and display the result on the screen.

Now we can reuse it to solve various problems without changing the source code of the program. To do this, you need to start the program and after starting the program, enter two numbers from the keyboard, pressing the key after each number Enter. Then the program will print the result itself.

Problems

Subscribe to receive updates!

Be up-to-date with our recent updates, new problems and answers!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Our courses

Where do you hold your classes?
We hold our classes online or on-site on Saturdays at our branch in Pimlico Academy, London.
You can find our timetable here.
What do you need to start learning online?
For lessons you only need a computer or phone with a microphone, camera and Internet access. Wherever you are - in London, Nottingham, New York or Bali - online lessons will be at hand.
When can I take the introductory lesson?
You can get acquainted with the school at any time convenient for you. To do this, just leave a request and sign up for a lesson.
I can't attend class, what should I do?
It is OK, it happens! Students have the opportunity to cancel a lesson up to 8 hours before the scheduled time without loss of payment. So you can reschedule it for a convenient time, and the teacher will have the opportunity to
I don't have much free time, will I have time to study?
Learning can take place at your own pace. We will select a convenient schedule and at any time we will help you change the schedule, take a break or adjust the program.
How long is one lesson?
All classes last 1 hour.
Hear from some of our amazing students who already achieved incredible results with us!
"Olympiad Maths Lessons helped me a lot to get the Gold medal in Junior Maths Challenge"
St. Paul's Student
"Thanks to the 'Data Science' and 'Coding in Python' lessons I got accepted to my dream university."
Michael
Data Science Student
Warwick University
"Great courses, which thoroughly explained topics beyond the capability of the GCSE answer sheet. Thanks so much."
Ivan
GCSE Student in Dubai
"Financial Mathematics! Best course to understand Python and Mathematics behind Finance!"
Gleb
VC Investor
"We got silver in PMC! Thanks George!"
Mum of St. Paul's Student
Prepare for the Primary Maths Challenge
"My daughter took a batch of 10 classes with George to understand Python with Turtle. I found George extremely knowledgeable and accessible."
Dad of Latymer School Student
Python with Turtle
We’re hiring!

Meet our team

Our teachers will tell you how to prepare for exams, help you cope with difficult tasks and win the Olympiad

They will tell you about the pitfalls of exams and the most common mistakes, and explain how to avoid them
George Ionitsa
Founder &
Teacher of Maths and Coding