Averting shutdown by chance If the chance is 20%, the shutdown will fail! The chance of shutdown success is 70%.
import random def shutdown(chance): if chance > 1: chance = chance / 100 random_num = random.random() if random_num > chance: print('shutdown succeed') else: print('shutdown failed') shutdown(20)