本文主要是介绍python写的一个小汽车程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#献给天底下所有跟我一样当爸爸的猿类
import os
#清除屏幕
def clear():
os.system('cls')
#绘制车体
def paint_body(num,startc):
c=startc
for index in range(num):
c = c + ' -'
print(c)
#绘制车轮
def paint_wheel(startc):
c=startc
for index in range(1):
c = c + ' '
for index in range(10):
c = c + ' -'
for index in range(10):
c = c + ' '
for index in range(10):
c = c + ' -'
print(c)
c = startc
for index in range(2):
c = c + ' '
for index in range(8):
c = c + ' -'
for index in range(12):
c = c + ' '
for index in range(9):
c = c + ' -'
print(c)
c = startc
for index in range(3):
c = c + ' '
for index in range(7):
c = c + ' -'
for index in range(14):
c = c + ' '
for index in range(6):
c = c + ' -'
print(c)
c = startc
for index in range(4):
c = c + ' '
for index in range(6):
c = c + ' -'
for index in range(15):
c = c + ' '
for index in range(5):
c = c + ' -'
print(c)
#绘制马路
def paint_road(num,startc):
c = startc
for index in range(num):
c = c + ' -'
print(c)
#绘制小汽车
def paint_car(startc):
#绘制顶部
paint_body(num=24,startc=startc)
paint_body(num=26,startc=startc)
paint_body(num=28,startc=startc)
paint_body(num=33,startc=startc)
paint_body(num=33,startc=startc)
paint_body(num=32,startc=startc)
#绘制车轮
paint_wheel(startc=startc)
#绘制马路
paint_road(num=34,startc=startc)
#主程序
s=' '
for space in range(50):
clear();s = s + ' ' ;paint_car(startc = s)
#将文件另存为car.py,然后使用命令行全屏,执行 python car.py,孩子一定喜欢
这篇关于python写的一个小汽车程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!