Python Programming Exercises (i)

Source: Internet
Author: User

Learning, are from the book to find some of the programming of small exercises.

1, write a program, he takes the radius of the sphere (floating point) as input, and output the sphere diameter, circumference length, surface area, volume.

defBall (): whileTrue:Try: P= 3.14R= Float (Input ("Please enter sphere radius:"))            ifR <=0:Print("the sphere radius of the input cannot be less than 0! ")            Else:                Print("the diameter of the sphere is:%.3f"% (r*2))                Print("the circumference length of the sphere is:%.3f"% (2*p*R))Print("the surface area of the sphere is:%.3f"% (4*p* (r**2)))                Print("the volume of the sphere is:%.3f"% ((4/3) *p*pow (r,3)))                 Break        exceptValueError:Print("input Error, please enter a number! ")if __name__=="__main__": Ball ()

Python Programming Exercises (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.