Python Practice-Looping

Source: Internet
Author: User
Tags for in range

1. Enter the value of N to find the factorial of N.

1 s=12 n = Int (input (" Please enter a number "))3for in Range (1,n+1):4     s=s*i5print(s)     

2, Origami on the moon
Everyone has seen the sci-fi film "Mars Rescue The Martian" bar, the movie astronauts in space encounter all kinds of situations are computer simulation, calculation to solve the problem.
We can also solve problems on the Earth by the Python language on the tall. Now the question is: we all know that the moon orbits the Earth in an elliptical orbit,
So the distance between the two is constantly changing, and their minimum distance is 363300 km. Now we all want to travel to the moon (the earth is tired, want to change a taste),
But we can hardly wait to take a rocket to the sky and bring a couple of hot ones. Good news, good news, manufacturers now developed a reverse celestial technology-origami on the moon!
Just a big piece of A4 paper, 0.088 mm thick, 0.176 mm fold once, two times 0.352 mm. A few more folds will be very high.
Put on the emergency clothing, take the mountain stick, take the selfie stick, we can climb to the moon to make friends circle. I just wanted to ask: how many times do we need to fold the ball last month?

1 count = 02 n = 0.0883 while 1:4     if(n> =363300*1000*1000):5break         6     n=n*27     count= Count+18Print(count)

3, summation s= A + AA + AAA + ... + aa...a value (number of a in the last number is N), where A is a 1~9 number, for example: 2 + 22 + 222 + 2222 + 22222 (at this time a=2 n=5)
Enter: One line, including two integers, 1th A, 2nd N (1≤a≤9,1≤n≤9), separated by commas.
Output: The value of a row, S.
Input example: 2,5 corresponding output: 24690

1 count = 02 sum = 23 a,n = eval (input (" Please enter two integers, separated by commas " ))4 for in Range (0,n):5     count = count+sum  6     sum = sum*10+27print(count)    

4, the calculation of basketball bounce height
Bookworm is a nerd, playing a basketball brain is not idle. This kind of person says nice call ' geek ', say not good is called ' nerd '.
This is not, the nerd looked at the basketball to think: If the basketball falls from a certain height, bounces back to the original height the half falls again after each landing.
So when the ball landed on the 10th time, how many meters did it pass? How high is the 10th time rebound? (Did you ask me if this question was fabricated?) Of course, when have you ever seen a nerd play basketball? )
Input: Enter an integer h, measured in meters, indicating the initial height of the ball.
Output: The output contains two lines:
Line 1th: To the 10th time the ball landed, the total distance passed.
Line 2nd: The height of the 10th bounce.
For example input: 20 corresponds to output: First line: 59.921875 second line: 0.01953125

1 # Basketball Problems 2 h = eval (input (" Please enter the height of the initial ball "))3 sum = h4 a = 0 5  for  in range (0,9):6        h=h/27        sum=sum+h*28Print (SUM,H/2)      

5, China's existing population of 1.3 billion, the annual growth of 0.8%, the preparation of procedures, calculate how many years to reach 2.6 billion?

1 num =2 count = 03 while 1:4     if num> =20:5break         6     num=num* (1+0.008)7     count=count+18print(count)           

6, on the screen output small 99 multiplication table (triangular form).

1  forIinchRange (1,10):2      forJinchRange (1,10):3         PrintI"*"J"=", I*j."\ t". end="")4     Else:5         Print("")


7, Beg 1! +2! +3! +4! +5! The and.

1 # The sum of factorial 2 sum=13 count=04 for in range (1,6):5         sum=i*sum6         count=count+sum7print(count)        8         


8, asterisk triangle: Read into an integer n,n is an odd number, the output consists of an asterisk character equilateral triangle, requires: line 1th 1 asterisks, line 2nd 3 asterisks, line 3rd 5 asterisks, and so on, the last line of a total of n asterisks.
Input: 3
Output:
*
***

1n= Int (Input ('number of input lines:'))2  forIinchRange (0,n+1):  3          forJinchRange (0,n-i):4             Print(end=' ')  5          forKinchRange (ni,n):6             Print('*', end=' ')  7         Print("')

Python Practice-Looping

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.