# your code goes here
import random
stulya = {
"S pikami" : { "weight" : 4 } , # 50%
"S huyami" : { "weight" : 3 } , # 37.5%
"Norm" : { "weight" : 1 } # 12.5%
}
start = 0
points = [ ]
for key, value in stulya.items ( ) :
start += value[ "weight" ]
points.append ( { "point" : start, "key" : key } )
a = sorted ( points, key= lambda s: s[ "point" ] )
choises = { key: 0 for key in stulya.keys ( ) }
for i in range ( 100000 ) :
choise = random .uniform ( 0 , start)
left = 0
for p in points:
if left < choise <= p[ "point" ] :
choises[ p[ "key" ] ] += 1
break
print ( choises)
total = sum ( [ c for c in choises.values ( ) ] )
print ( "Vsego vibiraly {} raz" .format ( total) )
for key, value in choises.items ( ) :
print ( "Varant '{}' vipal {} raz ili v {}% sluchaev" .format ( key, value, value*100 /total) )
CiMgeW91ciBjb2RlIGdvZXMgaGVyZQppbXBvcnQgcmFuZG9tCnN0dWx5YSA9IHsKCSJTIHBpa2FtaSIgOiB7IndlaWdodCI6IDR9LCMgNTAlCgkiUyBodXlhbWkiOiB7IndlaWdodCI6IDN9LCAjIDM3LjUlCgkiTm9ybSI6IHsid2VpZ2h0IjogMX0gIyAxMi41JQoJfQoKc3RhcnQgPSAwCnBvaW50cyA9IFtdCmZvciBrZXksIHZhbHVlIGluIHN0dWx5YS5pdGVtcygpOgoJc3RhcnQgKz0gdmFsdWVbIndlaWdodCJdCglwb2ludHMuYXBwZW5kKHsgInBvaW50Ijogc3RhcnQsICJrZXkiOiBrZXkgfSkKYSA9IHNvcnRlZChwb2ludHMsIGtleT1sYW1iZGEgczogc1sicG9pbnQiXSkKCmNob2lzZXMgPSB7IGtleTogMCBmb3Iga2V5IGluIHN0dWx5YS5rZXlzKCl9Cgpmb3IgaSBpbiByYW5nZSgxMDAwMDApOgoJY2hvaXNlID0gcmFuZG9tLnVuaWZvcm0oMCwgc3RhcnQpCglsZWZ0ID0gMAoJZm9yIHAgaW4gcG9pbnRzOgoJCWlmIGxlZnQgPCBjaG9pc2UgPD0gcFsicG9pbnQiXToKCQkJY2hvaXNlc1twWyJrZXkiXV0gKz0gMQoJCQlicmVhawoKCnByaW50KGNob2lzZXMpCnRvdGFsID0gc3VtKFtjIGZvciBjIGluIGNob2lzZXMudmFsdWVzKCldKQpwcmludCgiVnNlZ28gdmliaXJhbHkge30gcmF6Ii5mb3JtYXQodG90YWwpKQpmb3Iga2V5LCB2YWx1ZSBpbiBjaG9pc2VzLml0ZW1zKCk6CglwcmludCgiVmFyYW50ICd7fScgdmlwYWwge30gcmF6IGlsaSB2IHt9JSBzbHVjaGFldiIuZm9ybWF0KGtleSwgdmFsdWUsIHZhbHVlKjEwMC90b3RhbCkpCgoKCgoKCg==