python练习demo

python练习demo
1.

#coding:utf-8
age=input("输入你的年龄\n")
if age>18:
    print "大于十八岁"
    print "你成年了"
else:
    print "小于等于十八岁"
    print "还未成年"

2.

class Animals():
    def breathe(self):
        print " breathing"
    def move(self):
        print "moving"
    def eat (self):
        print "eating food"
class Mammals(Animals):
    def breastfeed(self):
        print "feeding young"
class Cats(Mammals):
    def __init__(self, spots):
        self.spots = spots
    def catch_mouse(self):
        print "catch mouse"
    def left_foot_forward(self):
        print "left foot forward"
    def left_foot_backward(self):
        print "left foot backward"
    def dance(self):
        self.left_foot_forward()
        self.left_foot_backward()
        self.left_foot_forward()
        self.left_foot_backward()
kitty=Cats(10)
print kitty.spots
kitty.dance()
kitty.breastfeed()
kitty.move()

3.

#coding:utf-8
num=input("please input your class number:")
if num==1 or num==2:
    print "class room 302"
elif num==3:
    print "class room 303"
elif num==4:
    print "class room 304"
else:
    print "class room 305"

4.

import tensorflow as tf
a=tf.constant([1.0,2.0])
b=tf.constant([3.0,4.0])
result=a+b
print result

5.

import turtle
t=turtle.Pen()
for i in rang(0,4):
    t.froward(100)
    t.left(40)  

t.reset()        
i=0
while True:
      t.froward(100)
      t.left(40)
      i=i+1
      if i==4:
          break   

6.

#文件读操作
import pickle
load_game_data={"MONEY":160}
load_file=open("save.dat","rd")
load_game_data=pikle.load(load_file)
load_file.close()
#文件写操作
import pickle
game_data={"POSITION":"E3"}
save_file=open("save.dat","wd")
pickle.dump(game_data,save_file)
save_file.close()

你可能感兴趣的:(python)