03 python小项目:做一个小游戏,猜猜我在想什么
如下:
print("—————————小仙女————————")
temp = input("不妨猜一下小仙女心里想的哪个数字:")
guess = int(temp)
if guess == 8:
print ("妈耶你是小仙女心里的蛔虫吗?")
print ("哼,猜中了也没有奖励!")
else:
print ("猜错啦,我现在想的是8!")
print ("游戏结束,不玩啦!")
1 提示功能,按tab就可以下拉查看相关的函数
2 input是让用户的输入
3 guess == 两个等号是表示等于,而单个=表示给等号那边一个值
4 bif是啥?
build in fuctions
是内置程序
5 input 是要求用户输入东西
temp是提取参数
int是取整数部分
guess 就是猜
6 tips:
在 if guess == 8 后面要加 :
else也要加:
print("hello world")
temp = input ("guess which number i am thinking?")
guess = int(temp)
if guess == 0:
print ("bad ass! you are right!\n you are my friend ooo")
else:
print("I am thinking of 0\n now game over")
===
重新写了一个。
整个思路流程就是
1 让电脑打一个 hello world——用print函数
2 让用户输入一个数值,并读取这个参数,用input引导,用temp把输入的玩意儿变成参数。
(temp是参数,input是叫用户输入)
3 然后定义guess的数值,需要让int函数来提取temp,变成一个数字
4 if and else 的逻辑
每个if句结束了要加冒号:
全程都要用英文输入法哦!