By huntz4k
I need to ask user question in Python 3. User will input float number. What data type,or combination should I use to then use that number in math operation deeper in program?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello @huntz4k ,
There is no such method, that can be used to take input as a float directly – but input string can be converted into a float by using float() function which accepts a string or a number and returns a float value. Here is a block of code which converts the user input to float(), prints the number and its data type.
# reading a value, converting to float
# printing value and it's type
val = float(input("Enter any number: "))
print("value of val2: ", val)
print("type of val2: ", type(val))
Please check this tutorial to do math operations https://www.digitalocean.com/community/tutorials/how-to-do-math-in-python-3-with-operators
Hope this helps!
Cheers, Lalitha
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.