我试图让一个用python2编写的琐碎游戏的代码在python3中运行。这是我到目前为止所得到的,但我在这一点上太困惑了。所有的选择题答案都不会显示(只有数字)。在# the start of a state trivia game

import random

# create placeholder lists for 50 items each

state = list(range(50))

capital = list(range(50))

date = list(range(50))

flower = list(range(50))

bird = list(range(50))

# populate the lists

state[0] = "Alabama"

capital[0] = "Montgomery"

date[0] = "December 14, 1819"

flower[0] = "Camellia"

bird[0] = "Yellowhammer"

state[1] = "Alaska"

capital[1] = "Juneau"

date[1] = "January 3, 1959"

flower[1] = "Forget-me-not"

bird[1] = "Willow Ptarmigan"

state[2] = "Arizona"

capital[2] = "Phoenix"

date[2] = "February 14, 1912"

flower[2] = "Suguaro Cactus Blossom"

bird[2] = "Cactus Wren"

state[3] = "Arkansas"

capital[3] = "Little Rock"

date[3] = "June 15, 1836"

flower[3] = "Apple Blossom"

bird[3] = "Mockingbird"

state[4] = "California"

capital[4] = "Sacremento"

date[4] = "September 9, 1850"

flower[4] = "Golden Poppy"

bird[4] = "California Valley Quail"

state[5] = "Colorado"

capital[5] = "Denver"

date[5] = "August 1, 1876"

flower[5] = "Mountain Columbine"

bird[5] = "Lark Bunting"

state[6] = "Connecticut"

capital[6] = "Hartford"

date[6] = "January 9, 1788"

flower[6] = "Mountain Laurel"

bird[6] = "Robin"

state[7] = "Florida"

capital[7] = "Tallahassee"

date[7] = "March 3, 1845"

flower[7] = "Orange Blossom"

bird[7] = "Mockingbird"

state[8] = "Georgia"

capital[8] = "Atlanta"

date[8] = "January 2, 1788"

flower[8] = "Cherokee Rose"

bird[8] = "Brown Thrasher"

state[9] = "Hawaii"

capital[9] = "Honolulu"

date[9] = "August 21, 1959"

flower[9] = "Red Hibiscus"

bird[9] = "Nene (Hawaiian Goose)"

state[10] = "Idaho"

capital[10] = "Boise"

date[10] = "July 3, 1890"

flower[10] = "Syringa"

bird[10] = "Mountain Bluebird"

state[11] = "Illinois"

capital[11] = "Springfield"

date[11] = "December 3, 1818"

flower[11] = "Violet"

bird[11] = "Cardinal"

state[12] = "Indiana"

capital[12] = "Indianapolis"

date[12] = "December 11, 1816"

flower[12] = "Peony"

bird[12] = "Cardinal"

state[13] = "Iowa"

capital[13] = "Des Moines"

date[13] = "December 28, 1846"

flower[13] = "Wild Rose"

bird[13] = "Eastern Goldfinch"

state[14] = "Kansas"

capital[14] = "Topeka"

date[14] = "January 29, 1861"

flower[14] = "Sunflower"

bird[14] = "Western Meadowlark"

state[15] = "Kentucky"

capital[15] = "Frankfort"

date[15] = "June 1, 1792"

flower[15] = "Goldenrod"

bird[15] = "Cardinal"

state[16] = "Louisiana"

capital[16] = "Baton Rouge"

date[16] = "April 30, 1812"

flower[16] = "Magnolia"

bird[16] = "Eastern Brown Pelican"

state[17] = "Maine"

capital[17] = "Augusta"

date[17] = "March 15, 1820"

flower[17] = "Pine Cone & Tassel"

bird[17] = "Chickadee"

state[18] = "Tennessee"

capital[18] = "Nashville"

date[18] = "June 1, 1796"

flower[18] = "Iris"

bird[18] = "Mockingbird"

state[19] = "Maryland"

capital[19] = "Annapolis"

date[19] = "April 28, 1788"

flower[19] = "Black-eyed Susan"

bird[19] = "Baltimore Oriole"

state[20] = "Delaware"

capital[20] = "Dover"

date[20] = "December 7, 1787"

flower[20] = "Peach Blossom"

bird[20] = "Blue Hen Chicken"

state[21] = "Massachusetts"

capital[21] = "Boston"

date[21] = "February 6, 1788"

flower[21] = "Mayflower"

bird[21] = "Chickadee"

state[22] = "Rhode Island"

capital[22] = "Providence"

date[22] = "May 29, 1790"

flower[22] = "Violet"

bird[22] = "Rhode Island Red"

state[23] = "Minnesota"

capital[23] = "St. Paul"

date[23] = "May 11, 1858"

flower[23] = "Lady-slipper"

bird[23] = "Loon"

state[24] = "Mississippi"

capital[24] = "Jackson"

date[24] = "December 10, 1817"

flower[24] = "Magnolia"

bird[24] = "Mockingbird"

state[25] = "Missouri"

capital[25] = "Jefferson City"

date[25] = "August 10, 1821"

flower[25] = "Hawthorn"

bird[25] = "Bluebird"

state[26] = "Michigan"

capital[26] = "Lansing"

date[26] = "January 26, 1837"

flower[26] = "Apple Blossom"

bird[26] = "Robin"

state[27] = "Montana"

capital[27] = "Helena"

date[27] = "November 8, 1889"

flower[27] = "Bitterroot"

bird[27] = "Western Meadowlark"

state[28] = "Nebraska"

capital[28] = "Lincoln"

date[28] = "March 1, 1867"

flower[28] = "Goldenrod"

bird[28] = "Western Meadowlark"

state[29] = "Nevada"

capital[29] = "Carson City"

date[29] = "October 31, 1864"

flower[29] = "Sagebrush"

bird[29] = "Mountain Bluebird"

state[30] = "New Hampshire"

capital[30] = "Concord"

date[30] = "June 21, 1788"

flower[30] = "Purple Lilac"

bird[30] = "Purple Finch"

state[31] = "Vermont"

capital[31] = "Montpelier"

date[31] = "March 4, 1791"

flower[31] = "Red Clover"

bird[31] = "Hermit Thrush"

state[32] = "New Jersey"

capital[32] = "Trenton"

date[32] = "December 18, 1787"

flower[32] = "Violet"

bird[32] = "Eastern Goldfinch"

state[33] = "New Mexico"

capital[33] = "Santa Fe"

date[33] = "January 6, 1912"

flower[33] = "Yucca"

bird[33] = "Road Runner"

state[34] = "New York"

capital[34] = "Albany"

date[34] = "July 26, 1788"

flower[34] = "Rose"

bird[34] = "Bluebird"

state[35] = "North Carolina"

capital[35] = "Raleigh"

date[35] = "November 21, 1789"

flower[35] = "Flowering Dogwood"

bird[35] = "Cardinal"

state[36] = "Wyoming"

capital[36] = "Cheyenne"

date[36] = "July 10, 1890"

flower[36] = "Indian Paintbrush"

bird[36] = "Meadowlark"

state[37] = "North Dakota"

capital[37] = "Bismarck"

date[37] = "November 2, 1889"

flower[37] = "Prairie Rose"

bird[37] = "Meadowlark"

state[38] = "Ohio"

capital[38] = "Columbus"

date[38] = "March 1, 1803"

flower[38] = "Scarlet Carnation"

bird[38] = "Cardinal"

state[39] = "Oklahoma"

capital[39] = "Oklahoma City"

date[39] = "November 16, 1907"

flower[39] = "Mistletoe"

bird[39] = "Scissor-tailed Flycatcher"

state[40] = "Oregon"

capital[40] = "Salem"

date[40] = "February 14, 1859"

flower[40] = "Oregon Grape"

bird[40] = "Western Meadowlark"

state[41] = "Pennsylvania"

capital[41] = "Harrisburg"

date[41] = "December 12, 1787"

flower[41] = "Mountain Laurel"

bird[41] = "Ruffed Grouse"

state[42] = "South Carolina"

capital[42] = "Columbia"

date[42] = "May 23, 1788"

flower[42] = "Yellow Jessamine"

bird[42] = "Carolina Wren"

state[43] = "South Dakota"

capital[43] = "Pierre"

date[43] = "November 2, 1889"

flower[43] = "Pasqueflower"

bird[43] = "Ring-necked Pheasant"

state[44] = "Texas"

capital[44] = "Austin"

date[44] = "December 29, 1845"

flower[44] = "Bluebonnet"

bird[44] = "Mockingbird"

state[45] = "Utah"

capital[45] = "Salt Lake City"

date[45] = "January 4, 1896"

flower[45] = "Sego Lily"

bird[45] = "Sea Gull"

state[46] = "Virginia"

capital[46] = "Richmond"

date[46] = "June 26, 1788"

flower[46] = "Dogwood"

bird[46] = "Cardinal"

state[47] = "Washington"

capital[47] = "Olympia"

date[47] = "November 11, 1889"

flower[47] = "Coast Rhododendron"

bird[47] = "Willow Goldfinch"

state[48] = "West Virginia"

capital[48] = "Charleston"

date[48] = "June 20, 1863"

flower[48] = "Rhododendron"

bird[48] = "Cardinal"

state[49] = "Wisconsin"

capital[49] = "Madison"

date[49] = "May 29, 1848"

flower[49] = "Wood Violet"

bird[49] = "Robin"

def state_flower():

#ask a multiple choice question about the state flower with four possible answers

# pick a list of 4 unique integers from a list of integers 0 to 49

# the first integer will match the state in the question and the

# correct flower, the other 3 will be false choices

pick = random.sample(range(50), 4)

print("The state flower of %s is:" % state[pick[0]])

answer = list(range(4))

for k in range(4):

# a little trick, the correct answer ends with an invisible space

# rstrip() makes sure the flower name itself does not end with a space

if k == 0:

answer[k] = "%s " % flower[pick[k]].rstrip()

else:

answer[k] = "%s" % flower[pick[k]].rstrip()

# randomize the mutiple choice answers, chr(65+n) adds A), B) ...

choice = []

answer = range(4)

n = 0

for k in random.sample(range(4),4):

choice.append("%s) %s" % (chr(65+n), answer[k]))

print(choice[n])

n += 1

# get the answer and check it

letter = input("Select A, B, C or D: ")

correct_flag = False

for answer in choice:

# the one with the trailing space is correct

if answer.endswith(" "):

correct = answer

# does it contain the selected letter? For instance D)

if letter.upper()+')' in correct:

correct_flag = True

# show the result

if correct_flag == True:

print(correct ,"is correct!")

else:

print("The correct answer is", correct)

state_flower()

下面是我运行它时发生的情况,现在我完全不知道如何修复它。。。在

^{pr2}$

谢谢你的帮助!!!在

python3游戏代码_将python2编写的“小游戏”代码更新到python3时出现问题相关推荐

  1. c++编写手机小游戏代码_用C++编写的小游戏源代码

    展开全部 五子棋的代码: #include #include #include #include using namespace std; const int N=15;                ...

  2. python简单小游戏代码_一个简单的python小游戏---七彩同心圆

    本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理 用pygame做一个简单的python小游戏-七彩同心圆 玩法:每次点击鼠标时,会以鼠标为圆心,不断 ...

  3. python能制作游戏吗_如何用Python制作小游戏

    要想用Python制作小游戏,必须要安装一个插件Pygame 什么是Pygame Pygame是跨平台Python模块,专为电子游戏设计,包含图像.声音.建立在SDL基础上,允许实时电子游戏研发而无需 ...

  4. python实现小游戏论文_用Python实现童年小游戏俄罗斯方块

    在那个电子产品比较匮乏的年代,小游戏机 还是为数不多的游戏类电子产品,对小孩子更是有着不可抗拒的魔力,在当时如果哪个小孩买了一个小游戏机,大伙一定迅速围上去... 俄罗斯方块作为其中一款小游戏,尽管规 ...

  5. java中的龟兔赛跑代码_有关JAVA编写龟兔赛跑的游戏的问题。求助……

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 我这个程序龟兔是在直行跑道上,老师要求龟兔在环形跑道上赛跑,哪位高手可以帮忙改一改啊,只要改成在环形跑道上赛跑就可以.THANKS. import jav ...

  6. python谁是卧底游戏流程图_用python实现谁是卧底小游戏

    谁是卧底 谁是卧底也是深受很多人喜欢的游戏,起码要三人以上才能玩,大致分为几个阶段: 1.分配平民词语和卧底词语---> 2.玩家依次发言---> 3.根据发言投票认为谁是卧底---> ...

  7. 用python编写乒乓球小游戏--Turtle功能的应用

    用python编写乒乓球小游戏–Turtle功能的应用 python有很多功能强大的代码库,Turtle是一款用于游戏开发的代码库.通过编写乒乓球小游戏可以了解这个库的基本的代码的使用 先创建游戏的背 ...

  8. c++编写手机小游戏代码_经典小游戏大集合(C++ 源码)

    [实例简介] 五子棋 贪吃蛇 俄罗斯方块 黑白棋 连连看 推箱子 扫雷等7个小游戏 C++源码 VC6.0 下编译运行. [实例截图] [核心代码] 经典小游戏大集合(C源码) └── 经典小游戏大集 ...

  9. 50行python游戏代码_使用50行Python代码从零开始实现一个AI平衡小游戏

    使用50行Python代码从零开始实现一个AI平衡小游戏 发布时间:2020-10-23 09:26:14 来源:脚本之家 阅读:74 集智导读: 本文会为大家展示机器学习专家 Mike Shi 如何 ...

最新文章

  1. 设计模式C#实现(三)——外观模式
  2. 如何编写数据库存储过程?
  3. MapReduce的优化
  4. AgileEAS.NET平台之ORM设计器
  5. java mvc 断点续传_用SpringMVC 实现断点续传 (HTTP)
  6. Django(part6)--利用正则的组名进行关键字传参
  7. 断开的管道 java.io.IOException: Broken pipe 解决方法
  8. html 图片上放置按钮,用CSS在图片上再加一个小按钮
  9. 转:javascript方法--bind()
  10. 大数据量分页存储过程效率测试附代码
  11. sql 大于某个日期_图解面试题:如何比较日期数据?
  12. spring boot +spring security + jwt 实现认证模块
  13. java物业收费管理系统源码_基于java+swing+mysql的物业小区收费管理系统
  14. android Activity设置透明主题样式方法
  15. IE浏览器验证码不刷新
  16. Log4j发送日志到服务器上
  17. 最小二乘法及应用实例
  18. 10047.GNU Make 使用手册中译版(转)
  19. 研发工程师面试题整理
  20. 这是我见过描写天津女孩中最真实的

热门文章

  1. Acunetix 简介 为什么需要保护您的 Web 应用程序
  2. Sitemap的介绍以及如何使用
  3. android官方下载,android studio2.2下载
  4. SpringCloud 第八期 Sentinel 熔断限流
  5. move_base源码解析
  6. 不是吧,不是吧,居然有比B+Tree更快的一种查询结构
  7. 如何在本地建立服务器以后使得外网可以访问(nat123)
  8. VMware虚拟机用CommVault备份后快照无法整合的真相!
  9. 八旋翼设计,垂直起降!世界上最小的飞行汽车来了
  10. 【项目设计】基于HLW8110计量芯片的电量计设计