Python编程挑战-1-5

We’ve partnered with our friends at Interview Cake to bring you a programming challenge to test your logic skills and abilities.

我们与Interview Cake的朋友合作,为您带来编程挑战,以测试您的逻辑技能和能力。

Updated 10/16/2015: Added additional challenges – cheers!

2015年10月16日更新:添加了更多挑战-加油!

挑战 (The Challenge)

  1. There are two players.
  2. Each player writes a number, hidden from the other player. It can be any integer 1 or greater.
  3. The players reveal their numbers.
  4. Whoever chose the lower number gets 1 point, unless the lower number is lower by only 1, then the player with the higher number gets 2 points.
  5. If they both chose the same number, neither player gets a point.
  6. This repeats, and the game ends when one player has 5 points.
  1. 有两个球员。
  2. 每个玩家都写一个号码,对其他玩家不可见。 它可以是1或更大的整数。
  3. 玩家显示他们的号码。
  4. 谁选择了较低的数字将获得1分,除非较低的数字仅降低1,那么数字较高的玩家将获得2分。
  5. 如果他们都选择了相同的数字,则没有人获得积分。
  6. 重复此过程,当一名玩家获得5分时游戏结束。

The challenge is to write a script to play this game. Knowing the rules and all your opponent’s previous numbers, can you program a strategy? (And, no – return random.randint(1, 3) is not a strategy.) You should really try playing this first with your friends – you’ll see there’s a deep human element to predicting your opponent’s choice.

挑战是编写一个脚本来玩这个游戏。 了解规则和对手的所有先前数字后,您可以制定策略了吗? (而且,不- return random.randint(1, 3)不是一种策略。)您应该首先尝试与朋友一起玩这个游戏-您会发现预测对手的选择有深远的人情味。

Is it possible to program a strong strategy?

可以制定一个强有力的战略吗?

Want to make the strategy a bit more interesting? Add an additional constraint to the challenge so that players can only use each number once. The first ten working submissions get a free copy of Real Python! (still open to submissions)

想要使该策略更有趣吗? 向挑战添加其他限制,以便玩家只能使用每个号码一次。 前十个提交的工作可免费获得Real Python! (仍然对提交内容开放)

奖品 (The Prizes)

Need some motivation? We’ll be giving out prizes to the strategies that perform the best:

需要动力吗? 我们将奖励表现最佳的策略:

Although the challenge is officially over (results) you can still partake! First, see if you can beat the current winner to receive $20 off of Real Python. Second, create a web application with Flask that (a) makes it easy to add a new strategy and then (b) runs a given strategy against all the other strategies.

尽管挑战已经正式结束( 结果 ),您仍然可以参加! 首先,看看您是否可以击败当前的赢家,获得Real Python的20美元折扣。 其次,使用Flask创建一个Web应用程序,该应用程序(a)可以轻松添加新策略,然后(b)针对所有其他策略运行给定策略。

等级 (Grading)

翻译自: https://www.pybloggers.com/2015/09/python-programming-challenge-first-to-five/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值