联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2025-11-15 12:20

Q2.1 Create a deck of cards

5 Points

Create a new global list variable named deck that represents a deck of cards. There should be 52 items in your list that represent the cards in a standard deck. Each card should be represented using its number and its suit where S-Spaces, D-Diamonds, H-Hearts, C-Clubs. So the cards in your deck should be:

AS, 2S, 3S, 4S, ..., 10S, JS, QS, KS, AC, 1C, ..., QC, KC, AD, 2D, ..., QD, KD, AH, 2H, ..., QH, KH

You may create the list by typing in all the cards, or (recommended) create an empty list and then use loops and add blocks to put the items into the list. Note: When you create a new list in Snap! it will have one blank element in it by default, so it's not actually. To make it empty, you need to click the left arrow on the list block to remove the blank element.

Run your program, and then upload the following:

1. A screenshot of your code

2. One or more screenshots of the values in the list. You need to show all the values in the list, so you may need more than one screenshot for this.

Q2.2 Shuffle the deck

15 Points

Write a reporter block that takes one parameter of type list. It should report a new list which is the shuffled version of the list that was passed to the parameter. You can do this using the following algorithm:

1. Create a new script. variable (you might need more than one script. variable) then set its value to a new empty list (remember to remove the blank element)

2. As long as there are still elements in the list passed in:

   1. Choose one of the remaining elements at random.

   2. Remove it from the parameter list and add it to the end of the new list.

3. Return (report) the new list.

Finally, use your new block to shuffle deck by setting the value of your deck variable to the value returned by your shuffle block.

Run your program, and then upload the following:

1. A screenshot of your code (including the code in the shuffle procedure)

2. One or more screenshots of the values in the list. You need to show all the values in the list, so you may need more than one screenshot for this.




版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp