Skip to content

Instantly share code, notes, and snippets.

@alenbasic
Created May 22, 2013 13:26
Show Gist options
  • Save alenbasic/5627525 to your computer and use it in GitHub Desktop.
Save alenbasic/5627525 to your computer and use it in GitHub Desktop.
A CLI implementation of the game Petals Around the Rose.
from random import randrange
a = "+-------+ "
b = ["| | ","|* | ","|* *| "]
c = ["| | ","| * | ","|* *| "]
d = ["| | ","| *| ","|* *| "]
while True:
count = 0
top = ''
row_one = ''
row_two = ''
row_three = ''
for i in range(5):
petal = randrange(0,3)
if petal == 0:
rose = 1
elif petal == 1:
rose = randrange(0,2)
else:
rose = randrange(0,3)
if rose == 1:
count += petal * 2
top += a
row_one += b[petal]
row_two += c[rose]
row_three += d[petal]
print(top)
print(row_one)
print(row_two)
print(row_three)
print(top)
choice = int(input("Please enter your answer: "))
if choice != count:
print("Sorry, the correct answer is %d" % count)
else:
print("That's right, the answer is %d" % count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment