Python Practice Notes

Source: Internet
Author: User
Tags greatest common divisor

These skills C language 100 examples of practice, helpless VC + + environment is really confused, even compile all have to error, let alone run. So continue yesterday's python.

First look at this way:

"Program 20"
Title: A ball from the height of 100 meters of freedom falling, each landing back to the original height of half, and then down, to ask it to fall on the 10th time, the total number of meters? How high is the 10th time rebound?

Nice little question, to review the code:

1 #!/usr/bin/env python2 #-*-coding:cp936-*-3 Print" "title: A ball from 100 meters height of freedom falling, each landing after jumping back to the original height of half;4 How many meters are there in the 10th time when landing? How high is the 10th time rebound? 5 " "6 7Raw_input ("Press any key to continue \ n")8Raw_input ("* Want me to help you count it? Press ENTER to start * \ n")9n = Int (raw_input ("* * How many times are you going to bounce? Put the numbers below * * \ n"))TenD = 0.0 One #Nth Fall Bounce Height A Print "Nth Fall Bounce Height:%s"% (100*1/2.0**N) -  - #how many meters are there in the nth time of landing? the  forIinchrange (n): -D + = 100*1/2.0**I - Print "The number of meters when the nth landing:%s\n"%D - #press ENTER to continue +Raw_input ("Press any key to exit")

Let's start with a little bit of knowledge about it:

The contents of the three quotation marks can be printed across lines and remain intact.

Division has "/" and "//" two kinds: the latter is only divisible, the decimal is all out; the first type is int, which is the same as the second one, with float holding decimals.

"* *" such two asterisk is a power operation, see for the first time.

That's about as much. But a little experience has to say, that is to write comments!

Not only helps others understand your code, but also makes yourself more clear when you write. Just write the first question, it is crazy, a few lines of code to write for one hours, write the back of the forgotten front, and debugging grammar errors will forget to debug this sentence is why! No bird!!

OK, keep on the next question.

"Program 18"

Title: The value of S=A+AA+AAA+AAAA+AA...A, where a is a number. For example 2+22+222+2222+22222 (there are 5 numbers added at this time), several numbers are added with keyboard control.

The key is to calculate the value of each item, the rest is good to deal with (but born with the defect of hand, grammar, wrong type, value is not valid, the bug has a lot of wood there, can code just a few lines have wood there ah! )

Not be bird myself.

Serving:

1 #!/usr/bin/env python2 #-*-coding:cp936-*-3 #Enter a number to overlay4a = Int (Raw_input ("Enter a number to overlay"))5 #Input Digital Control overlay number6x = Int (Raw_input ("number of input overlays"))7 #define a function to calculate the number of times the nth overlay should be added8 defDJ (x="", y=""):9s =0Ten      forIinchRange (1,y+1): Ones + = x * * * (i-1) A     returns - #calculate the result of the overlay, and print out the process together -s =a the PrintS, -  forIinchRange (2,1+x): -s + =DJ (a,i) -     Print "+%s"%(DJ (A,i)), + Print "=%s"%s - #press ENTER to continue +Raw_input ("Press Enter")

I don't want to say much. But there are 3 other questions worth mentioning. To calculate greatest common divisor!! I didn't do it!! As in the examination of the city in the way of binary hexadecimal I did not do the same, no more! Do you believe this?

Python Practice Notes

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.