C02 Python

Exercise

C02-1-1. Generate 100 numbers randomly, use bubble sort algorithm to sort. Please print the sorted numbers, and the max, min, mean.

C02-1-2. Input N, and D, output all twin prime pairs less than N of distance D.

C02-2-1. Input the number of nodes N and edge probability p, use networkx to generate an ER network. Please visualize the network, save the picture as an EPS file. Calculate the average degree, average betweenness centrality, plot degree distribution and betweenness centrality distribution.

Homework

C02-1-1. Input an integer N and output all possible solutions of Goldbach conjecture. For example, N=10, the program should output: 4=2+2, 6=3+3, 8=3+5, 10=3+7, 10=5+5.

C02-2-1. Input the number of nodes N, the distance D, and node ID i and j. Use networkx to generate a randome network of size N. Output all possible routes from node i to node j which are less or equal to D.

Material

Windows+Sublime+Python development environment Setup: https://www.jianshu.com/p/ca031bc9082b

Python Official Website: https://www.python.org

Python Official Documentation: https://docs.python.org/3/tutorial

Anaconda Python distribution: https://www.anaconda.com/distribution

Numpy Tutorial: https://docs.scipy.org/doc/numpy/user/quickstart.html

Networkx Python Packages: https://networkx.github.io

Literature

[1] J. Bovy. galpy: A python LIBRARY FOR GALACTIC DYNAMICS. The Astrophysical Journal Sup- plement Series, 216(2):29, feb 2015.

[2] G. van Rossum and P. D. Team. Python 3.6 Extending and Embedding Python. Samurai Media Limited, United Kingdom, 2016.