树莓派怎样使用python编程
2个回答
展开全部
树莓派准确来说就是一台廉价的安装了linux OS的主机,最初的目的是以低价硬件及自由软件刺激在学校的基本的电脑科学教育。所以如果你要学习编程并且不是特别缺钱的话其实买一台便宜的PC机更合适,更容易上手。因为如果你对linux不熟悉可能会遇到各种各样的问题。
回到学习编程的问题上,既然树莓派只是一台更廉价的主机,所以和你买一台pc然后安装linux系统是一样的。准确的说,如何学习编程同你在pc上还是在树莓派上没有关系。
回到学习编程的问题上,既然树莓派只是一台更廉价的主机,所以和你买一台pc然后安装linux系统是一样的。准确的说,如何学习编程同你在pc上还是在树莓派上没有关系。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#Python Adventure Game
import time
import random
#define variable health point
hp = 30
#define variable object_ to show what the adventurer has
object_=[]
#define variable what the game sets
tools = ["Torch","Rope","Spanner","50HP","10HP"]
#set two acceptable answers ,select any one to end loop
def get_input(prompt,accepted):
while True:
value = input(prompt).lower()
if value in accepted:
return value
else :
print("That is not a recognised answer,must be one of",accepted)
def handle_room(location) :
global hp
if location== "start":
print("You are stading on a path at the edge of a jungle.There is a cave to your left and a beach to your right.")
object_.append(random.choice(tools))
print("Lucky,you have gained",object_[-1])
use_tools(object_)
direction = get_input("Do you want to go left or right?",["left","right"])
if direction == "left":
return "cave"
elif direction == "right":
return "beach"
elif location == "cave":
print("On the entrance of cave,you find a torch!!!")
object_.append("Torch")
print("You walk to the cave and notice there is an opening.")
print("A small snake bites you,and you lose 20 health points.")
hp-=20
answer = get_input("Do you want to go deeper?(y/n)",["y","n"])
if answer == "y":
return "deep_cave"
elif answer == "n":
return "start"
elif location == "beach":
print("You walk to the beach but remember you do not have any swimwming equipment.")
print("The cool water revitalizes you.You have never felt more alive,gain 70 health points.")
hp+=70
answer = get_input("Do you want to go swimming?(y/n)",["y","n"])
if answer == "y":
return "sea"
elif answer == "n":
return "start"
elif location == "sea":
print("Suddenly there was a tsunami,you can't escape.")
hp=0
return "end"
else :
print("Programmer error,room",location,"is unknown")
return "end"
#define the function to use the tools of HP
def use_tools(tool):
global hp
length = len(tool)
for i in range(0,length):
if tool[i]=="50HP":
hp+=50
tool.pop(i)
print("You have use the tool of 50HP")
j+=1
elif tool[i]=="10HP":
hp+=10
tool.pop(i)
print("You have use the tool of 10HP")
j+=1
#The begin of the program.
location = "start"
#Loop until we reach the special "end" location
while location!="end":
location = handle_room(location)
#Check we are not dead each return
print("You now have",hp,"health points.")
if hp<=0:
print("You are dead.\nGame Over!!!")
break
print("Your adventure has ended,bye~")
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询