lundi 26 septembre 2016

Python 3 - How to randomize what text displays

I am a beginner at python and I am trying to figure out how I can randomly display text. For example, 60% chance of "Hello", 40% chance of saying "Goodbye", etc. Right now, for fun, I am trying to create sort of a bottle flip game. If you don't know what it is, its basically when you flip a half empty water bottle and try to land it. This is what I have: (This is more than likely completely wrong.)

import random

number = random.randrange(10)

if number == "1":

    print ("You have landed the bottle!")

elif number == "2":

    print ("You have landed the bottle!")

elif number == "3":

    print ("You have landed the bottle!")

elif number == "4":

    print ("You have landed the bottle!")

elif number == "5":

    print ("The bottle did not land, better luck next time.")

elif number == "6":

    print ("The bottle did not land, better luck next time.")

elif number == "7":

    print ("The bottle did not land, better luck next time.")

elif number == "8":

    print ("The bottle did not land, better luck next time.")

elif number == "9":

    print ("The bottle did not land, better luck next time.")

elif number == "10":

    print ("The bottle landed on the cap!")

Any help would be appreciated. - ICE




Aucun commentaire:

Enregistrer un commentaire