Python Forum
Zen Python Challenge
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Zen Python Challenge
#4
I've been wondering for a while if I could manage a rock-paper-scissors game with these constraints.

"""
zen_rps.py

A zen Python rock-scissors-paper program.
"""

import random

def zen_rps(rounds):
    win_loss_draw, wins = [0, 0, 0], {'rock': 'scissors', 'scissors': 'paper', 'paper': 'rock'}
    for round in range(rounds):
        you, me = input("What's your move? ").lower().strip(), random.choice(list(wins.keys()))
        win_loss_draw[1 + (you == me) - 4 * (wins.get(you, '') == me) + bool(print('My move is', me))] += 1
    return win_loss_draw
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Zen Python Challenge - by ichabod801 - Jul-26-2018, 01:38 PM
RE: Zen Python Challenge - by perfringo - Jul-26-2018, 02:18 PM
RE: Zen Python Challenge - by ichabod801 - Jul-26-2018, 04:59 PM
RE: Zen Python Challenge - by ichabod801 - Aug-13-2018, 12:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python 100 line Challenge codingCat 9 3,267 Jun-20-2022, 07:18 AM
Last Post: Coricoco_fr
  Python 25 Line Challenge codingCat 34 7,965 May-18-2022, 07:17 PM
Last Post: codingCat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020