- 安装编码工具Pycharm
下载地址https://www.jetbrains.com/pycharm/download/#section=mac
your activation code could not be validated error 1653219问题解决
顺便BB一句请支持正版Idea全家桶
- 创建项目然后编码
创建项目https://www.evget.com/article/2018/8/24/28417.html
代码案例来自于https://www.evget.com/article/2018/8/24/28417.html
代码结构:
附上代码:
Demo.py
class DemoOne:
def __init__(self):
self.speed = 0
self.odometer = 0
self.time = 0
def say_state(self):
print("I'm going {} kph!".format(self.speed))
def accelerate(self):
self.speed += 5
def brake(self):
self.speed -=5
def step(self):
self.odometer += self.speed
self.time += 1
def average_speed(self):
return self.odometer / self.time
main.py
from DemoOne.Demo import DemoOne
if __name__ == '__main__':
my_car = DemoOne()
print("I'm a car!")
while True:
action = input("What should I do? [A]accelerate, [B]brake, show [O]odometer, or show average [S]speed?").upper()
if action not in "ABOS" or len(action) != 1:
print("I don't know how to do that")
continue
if action == 'A':
my_car.accelerate()
elif action == 'B':
my_car.brake()
elif action == 'O':
print("The car has driven {} kilometers".format(my_car.odometer))
elif action == 's':
print("The car's average speed was {} kph".format(my_car.average_speed()))
my_car.step()
my_car.say_state()
建议手敲自己感受一遍总是好的
main的左边有一个绿色箭头,点击运行,在下面控制台可以进行简单的交互使用。