How can I get my program to print floats?

Snicklezs

I've written a small program to help me with my math homework:

import math
def saCircle():
    while True: 
        radius = float(raw_input("Enter the radius: "))
        print "\nFinding area with %d as the radius" % radius  
        x = math.pi * radius**2
        print "\nThe area of your circle is %d\n" % x 
saCircle() 

The problem is that it will accept a decimal number but it will not print out the value of the decimal number.

How can I fix this?

Idos

Use %f instead of %d (rounds your number to an integer) to print a float:

>>> radius = 4.4
>>> x = math.pi * radius**2
>>> print "\nThe area of your circle is %f\n" % x

The area of your circle is 60.821234

This question explains the difference very well.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

I can't seem to get my program to print the shortest word

From Dev

How can I make my program print its github version number with BSD?

From Dev

Why can't I print the first argument passed to my program?

From Dev

Why can't I print the first argument passed to my program?

From Dev

How can I print my outcome as a list?

From Dev

How can I print my outcome as a list?

From Dev

How can I make my program faster?

From Dev

How do I get my QML program to utilize Unity7 notifications? Is there an API I can use?

From Dev

How do I get my QML program to utilize Unity7 notifications? Is there an API I can use?

From Java

How can I get my print statement to work to where it prints the average score and the correlating letter grade?

From Dev

How can I make my program installable via the linux repositories (eg, using apt-get)?

From Dev

How can I get my Fortran program to use a certain amount of RAM?

From Dev

How can I get my VB GUI not to freeze while the program is running?

From Dev

How can I get my program to swap a string with the key that is pressed down in a specific section of the string?

From Dev

How can I get my program to check if a pressed key is in a selected word

From Dev

How can I get systemd to use qingy as my default tty program instead of agetty (debian jessie)?

From Dev

How can I get my program to swap a string with the key that is pressed down in a specific section of the string?

From Dev

C++ How can I get my program to display value instead of memory location?

From Dev

How can I get my C program to read more than one line of text from a file?

From Dev

How can i print my array and my histogram on the same line?

From Dev

How can I optimize my code for my Spanish Translation Program?

From Dev

How can I tell if my <List> is being used by my program?

From Dev

I can't get my card objects to print correctly

From Dev

I can't get my array to print alphabetically

From Dev

I can't get my python encryption program to work properly

From Dev

I can't get an answer out of my C++ program

From Dev

Making a valid password checker. Can not get my program to get through the if conditions to print a valid password

From Dev

How can I compress four floats into a string?

From Dev

How can I effectively use floats in equals()?

Related Related

  1. 1

    I can't seem to get my program to print the shortest word

  2. 2

    How can I make my program print its github version number with BSD?

  3. 3

    Why can't I print the first argument passed to my program?

  4. 4

    Why can't I print the first argument passed to my program?

  5. 5

    How can I print my outcome as a list?

  6. 6

    How can I print my outcome as a list?

  7. 7

    How can I make my program faster?

  8. 8

    How do I get my QML program to utilize Unity7 notifications? Is there an API I can use?

  9. 9

    How do I get my QML program to utilize Unity7 notifications? Is there an API I can use?

  10. 10

    How can I get my print statement to work to where it prints the average score and the correlating letter grade?

  11. 11

    How can I make my program installable via the linux repositories (eg, using apt-get)?

  12. 12

    How can I get my Fortran program to use a certain amount of RAM?

  13. 13

    How can I get my VB GUI not to freeze while the program is running?

  14. 14

    How can I get my program to swap a string with the key that is pressed down in a specific section of the string?

  15. 15

    How can I get my program to check if a pressed key is in a selected word

  16. 16

    How can I get systemd to use qingy as my default tty program instead of agetty (debian jessie)?

  17. 17

    How can I get my program to swap a string with the key that is pressed down in a specific section of the string?

  18. 18

    C++ How can I get my program to display value instead of memory location?

  19. 19

    How can I get my C program to read more than one line of text from a file?

  20. 20

    How can i print my array and my histogram on the same line?

  21. 21

    How can I optimize my code for my Spanish Translation Program?

  22. 22

    How can I tell if my <List> is being used by my program?

  23. 23

    I can't get my card objects to print correctly

  24. 24

    I can't get my array to print alphabetically

  25. 25

    I can't get my python encryption program to work properly

  26. 26

    I can't get an answer out of my C++ program

  27. 27

    Making a valid password checker. Can not get my program to get through the if conditions to print a valid password

  28. 28

    How can I compress four floats into a string?

  29. 29

    How can I effectively use floats in equals()?

HotTag

Archive