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.
Be up-to-date with our recent updates, new problems and answers!
Our goal at this course is to enhance our students’ mathematical intuition by focusing on a deep understanding of mathematical concepts and to enable them to link different concepts and apply their knowledge to solve mathematical problems to help them to improve their performance at Maths exams.
This course guides you through the fundamentals of Python programming using an interactive Python library known as Turtle.
This course encompasses a range of Geometry topics such as coordinate and spatial geometry, introductory trigonometry, angles, parallel lines, congruent and similar triangles, polygons, circles, the Pythagorean Theorem, and more. Emphasis will be placed on reinforcing Algebra skills and enhancing critical thinking through problem-solving in both mathematical and real-world contexts.