学习主题:Python写一个小游戏来学习基本操作
学习日期:2020-02-04
简单游戏-猜数字
print("Let us play a game--- guess the number");
TheNum=51;
temp=input('please input the number that your guessed ');
GuessNum= int(temp);
if GuessNum==TheNum : #这里要有冒号
print('Suceed, Pass') #这里必须要有缩近,Python严格要求缩近
else: #这里要有冒号
print('Failed, No Pass')#这里必须要有缩近,Python严格要求缩近
#记住没有end
print('Game over')
使用Tab键进行缩近。
点击F5键或者run就可以运行。
Python中缩近很重要,不同的缩近可能会执行出不同的结果或者会出现语法错误Syntax Error.
要学会使用其内置函数(BIF-build in function)
比如上面的代码中使用的input print等
查看Python中有哪些BIF,输入以下命令。
dir(__builtins__)#builtins前后都是两个下划线
上面罗列出了所有的内置函数,注意到这里面也有help,哈哈,这和matlab的help一样,这真是个好消息。
试着用下吧。比如查看print的用法。