# Example analysis of random module usage in python

Source: Internet
Author: User

This example describes the use of random modules in Python. Share to everyone for your reference. Specifically as follows:

?

 1 2 3 4 Import random x = Random.randint (1,4); y = Random.choice ([' Appale ', ' banana ', ' cherry ', ' durian ']); Print (x,y);

The results of the operation are as follows:

(2, ' cherry ')

No matter which language I study, I always like to get a random number to play. The Lunar New Year of November six, let ' s Python!!!

?

 1 2 3 4 5 6 7 8 L=[] While true:name=input ("Please enter a name:") if name!= ': L.append (name) else:break print (L);

?

 1 2 3 4 5 6 "' 1 to 100 direct all integers ' and ' ' X=range (1,101,1) sumi=0 for-I in x:sumi+=i print (Sumi)

The results of the operation are as follows:

5050

?

 1 2 3 4 5 6 7 8 9 10 U1= ' general method for factorial ' Print (U1) def JC (n): S=1 for I in Range (1,n+1): s*=i return s n = input ("n! Usage:: ") H = JC (int (n)) print (h)

The results of the operation are as follows:

?

 1 2 3 A general method for factorial n! Usage::5 120

?

 1 2 3 4 5 6 7 8 9 10 U2= ' "Factorial" "Print (U2) def jch (n): if (n==1): return 1 Else:return n*jch (n-1) un=input (" Input N: ") s=jch (int (un)) PRI NT ("n! Is ", s)

The results of the operation are as follows:

?

 1 2 3 Implement factorial input N:5 (' n! is ', 120) by recursion

I hope this article will help you with your Python programming.

Related Keywords:
Related Article

## E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD

Learn more >

### 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.