编写初学者游戏时遇到问题 [英] Having trouble coding a beginner game

查看:52
本文介绍了编写初学者游戏时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在学习的一本书中,有一个项目我必须创建一个名为猜猜我的号码的游戏。在这个游戏中,我从1到100中选择一个数字,然后让计算机猜出我的数字。我不知道代码如何控制我输入的数字

In a book that I''m learning, there is a project which I have to create a game called "Guess my number". In this game, I pick a number from 1 to 100 and let the computer guess my number. I don''t know how code control the numbers i type

展开 | 选择 | Wrap | 行号

推荐答案

展开 | 选择 | Wrap | 行号


您需要使用int()函数将raw_input转换为整数。因此,您可以使用整数比较(这将给出正确的结果),而不是字符串比较。

You need to convert your raw_input to an integer with the int() function. Thus, you can use integer comparisons (which will give the correct results), not string comparisons.

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号


非常感谢你的帮助。真的节省了我的时间。

我也有一个基于同一游戏的新问题。

thank you very much for all your help. really saved my time.
I also have a new question based on the same game.

展开 | 选择 < span class =codeDivider> | Wrap | 行号


这篇关于编写初学者游戏时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆