<｜begin▁of▁sentence｜>### Instruction:
Given a random graph generated by the Erdos-Renyi model with 100 vertices and edge probability of 0.1, where the edges and nodes have been assigned random weights, how can you use the community_leiden function of igraph to detect the community structure and to calculate its modularity?
### Response:
from igraph import Graph

# Create an example graph
g = Graph.Erdos_Renyi(n=100, p=0.1)

# Assign random weights to edges and nodes
import random
edge_weights = [random.uniform(0.5, 2.0) for _ in range(g.ecount())]
node_weights = [random.uniform(1, 10) for _ in range(g.vcount())]
g.es['weight'] = edge_weights
g.vs['weight'] = node_weights

# Run the Leiden algorithm
partition = g.community_leiden(edge_weights='weight', node_weights='weight', resolution=1.0, n_iterations=-1)

# Print the modularity of the partition
modularity = g.modularity(partition, weights='weight')
print('Modularity:', modularity)
<|EOT|>
