Work With Strings and Numbers (Exercise)
And you’ll continue with some more input exercises. This one is called Working With Strings and Numbers. Write a program that uses the
input() function twice to get two numbers from the user, multiplies the numbers together, and displays the result.
If the user enters
4, for example, the new program should print the following text:
The product of 2 and 4 is 8.0. What you can see here is that the result should be displayed as a floating-point number.
And then keep in mind that the
input() function always creates a string, that you can convert certain strings into actual numbers using the
int() and the
float() functions, and that you can convert numbers to strings using the string function,
00:45 So what you’ll have to do is user input collection, then type conversion, and then also a little bit of math and displaying it back to the user. Give it a try by yourself, and then if you want, you can watch the next lesson, where I’ll solve the task.
Become a Member to join the conversation.