Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 1.86 KB

File metadata and controls

59 lines (43 loc) · 1.86 KB

100 Plus Python Coding Problems With Solutions


User input to Number

The problem

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.

Hints

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.

Solution

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)

Try it on Programming Hero

Shortcut

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)

Try it on Programming Hero

Going Forward

Going forward, we will write input and conversion in one line.

Quiz

Which one is used to convert string to a number?

  1. number
  2. convert
  3. int or float
Show Answer

The answer is : 3

Take Away*

Use int or float to convert user input to a number.

  Next Page  

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