Take two inputs from the user. One will be an integer. The other will be a float number. Then multiply them to display the output.
Use input. By default, input gives you a string. Then use int and float to convert the input to a number. And then multiply them. That’s it.
int_text = input("Give me an integer number: ")
int_num = int(int_text)
float_text = input("Give me a float number: ")
float_num = float(float_text)
result = int_num * float_num
print("Your result is: ", result)You wrote input in one line and then in the next line you used int or float to convert the number. You can write the two lines in one line. Like below
int_num = int(input('Give me an integer number: '))
float_num = float(input('Give me a float number: '))
result = int_num * float_num
print('Your result is: ', result)Going forward, we will write input and conversion in one line.
Which one is used to convert string to a number?
- number
- convert
- int or float
Show Answer
The answer is : 3
Use int or float to convert user input to a number.
tags: programming-hero python python3 problem-solving programming coding-challenge interview learn-python python-tutorial programming-exercises programming-challenges programming-fundamentals programming-contest python-coding-challenges python-problem-solving
