Python _ does not need to print 1-1000 cyclically, and python prints 1-1000

Source: Internet
Author: User

Python _ does not need to print 1-1000 cyclically, and python prints 1-1000
Question: I can print the 1000 numbers from 1 to on the screen. Do not use cyclic or conditional statements. Do not use them? : Operator. You are not allowed to use the method of listing output statements in the source code. For example, if you cannot use one thousand print statements, you will not repeat other silly behaviors. Answer:

Import syssys. setrecursionlimit (1005) def pr (n): print '% d' % n # t = int (1/(n-1000) if n <1000: pr (n + 1) # return None # return Nonepr (1)
I checked on the Internet and found that the default recursive depth of python is very limited, probably more than 900. When the recursive depth exceeds this value, this exception will be thrown. The solution is to manually set the recursive call depth:
Import sys. setrecursionlimit (1000000) # For example, set this parameter to 1 million

 


How does python use the for Loop Control to execute a custom function multiple times?

# In the script, you can write the import randomdef R (): print (random. randint () for I in range (): R ()

Python will generate random numbers cyclically.

Yes. However, according to your actual needs, many times you cannot use high-quality random numbers. That is to say, you cannot perceive loops at all. The loops are large and won't happen after thousands of records.

If you really need it, python has Mersenne Twister code, and the random number quality is very high. There is also a/dev/random generator in linux that is close to a real random number.

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.