Ⅰ python怎么用星号画平行四边形菱形
defprintStar(intNum):
s="*"
spaceLength=intNum
blockCount=int(intNum/2+1)
foriinrange(spaceLength):
result=s.rjust(blockCount)
ifi>=int(spaceLength/2):
print(result)
s=s[2:]
blockCount-=1
else:
print(result)
s=s+(2*"*")
blockCount+=1
defoddOReven(intNum):
ifintNum%2==0:
print("pleaseinputaoddnumdata")
else:
printStar(intNum)
if__name__=='__main__':
whileTrue:
try:
intNum=eval(input("pleaseinputaoddnumdata "))
oddOReven(intNum)
exceptBaseExceptionase:
print("Pleaseinputas1/2/3...Errorcode:%s"%e)
结果如下:
希望可以帮到你,望采纳~
Ⅱ 如何用Python写星星符号
foriinrange(1,10):
if(i<=5):
x=i
else:
x=10-i
forjinrange(1,x+1):
print("*",end='')
print(" ")
Ⅲ 急求!这是一个用python画国旗的程序,请求大神解释一下每一步是干嘛的
import turtle //导入模块
import time
import os
def draw_square(org_x, org_y, x, y): //定义红旗绘制函数
turtle.setpos(org_x, org_y) //定义画笔初始位置
turtle.color('red', 'red') //颜色
turtle.begin_fill() //开始绘制
turtle.fd(x) //绘制偏转方向和角度
turtle.lt(90)
turtle.fd(y)
turtle.lt(90)
turtle.fd(x)
turtle.lt(90)
turtle.fd(y)
turtle.end_fill() //绘制结束
def draw_star(center_x, center_y, radius): //定义星星绘制函数
print(center_x, center_y) //显示位置
turtle.pencolor('black') //画笔轨迹颜色
turtle.setpos(center_x, center_y) //中心点位置
pt1 = turtle.pos() //偏转角度计算
turtle.circle(-radius, 360 / 5)
pt2 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt3 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt4 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt5 = turtle.pos()
turtle.color('yellow', 'yellow') //星星颜色
turtle.begin_fill() //开是绘制
turtle.goto(pt3)
turtle.goto(pt1)
turtle.goto(pt4)
turtle.goto(pt2)
turtle.goto(pt5)
turtle.end_fill() //绘制结束
print(turtle.pos())
turtle.pu() //隐藏画笔轨迹
draw_square(-320, -260, 660, 440) //绘制红旗
star_part_x = -320 //自定义星星大小等属性
star_part_y = -260 + 440
star_part_s = 660 / 30
center_x, center_y = star_part_x + star_part_s * 5, star_part_y - star_part_s * 5 //计算星星中心点位置
turtle.setpos(center_x, center_y)
turtle.lt(90)
draw_star(star_part_x + star_part_s * 5, star_part_y - star_part_s * 2, star_part_s * 3) //绘制星星
turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 2) //同上
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 4)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 7)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 9)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.ht()
time.sleep(5) //设置挂起时间
os._exit(1)
Ⅳ python 编程(菜鸟级)高手2分钟
#s = raw_input('Enter some words:')
#frame='*'
#context='*'
#i=0
#while (i<len(s)):
# frame='%s*'%(frame)
# context='%s%s'%(context,s[i])
# i+=1
#frame='%s*'%(frame)
#context='%s*'%(context)
#print '%s\n%s\n%s'%(frame,context,frame)
注意把#号去掉就可以了,我用了5分钟,看来我不是庆汪高手啊
以上代码只能在python 2.x运行
不能在python 3.x运行
1 在python3.x中你要把raw_input()改为input()
2 把print调用,誉备仔加上()
#s = input('Enter some words:')
#frame='*'
#context='*'
#i=0
#while (i<len(s)):
# frame='%s*'%(frame)
# context='%s%s'%(context,s[i])
# i+=1
#frame='%s*'%(frame)
#context='%s*'%(context)
#print('%s\n%s\滚姿n%s'%(frame,context,frame))
这样就可以在python 3.0中运行了
Ⅳ python输出星号只输出奇数行
首先解决星号个数问题。
输出星号数等于(循环变量i(从0开始)世李加1)乘2减1,接着是空格个数问题,尾行无空格,首行空格数等于星号岩返凳左空格(星号左右空格数相同)数乘2,星号左空格数等于(输入数加1)//2等于输出行数。
输出行数、输出粗旅星号数、输出空格数都解决了(左右都要输出空格才能通过)。
Ⅵ python星星怎么绘制
打开电脑,安装python3.6,打开Idle;进入Python语言编程环境后,点File(文件)下面的New file,新建一个文件;出现一个以untitled为默认文件名的窗口,下面是个空白的编辑页面;在空白的编辑页面处输入代码;选定一个保存位置,并给程序命名。
Ⅶ python绘图小结(2)
#例题1绘制一个四叶草
import turtle
turtle.color("green","green")
turtle.setheading(90)
turtle.begin_fill()
for i in range(4):
turtle.circle(-100,180)
turtle.left(90)
turtle.end_fill()
turtle.done()
#例题2绘制一个四角星
import turtle
turtle.color("yellow"配哪,"yellow")
turtle.begin_fill()
for i in range(4):
turtle.circle(100,90)
turtle.right(180)
turtle.end_fill()
turtle.done()
#例题3绘制一个四叶花瓣
import turtle
turtle.color("pink"饥宴,"pink")
turtle.begin_fill()
turtle.circle(-100,90)
turtle.right(90)
turtle.circle(-100,90)
turtle.circle(100, 90)
turtle.right(90)
turtle.circle(-100, -90)
turtle.right(90)
turtle.circle(-100, 90)
turtle.right(90)
turtle.circle(-100, 90)
turtle.circle(100, 90)
turtle.right(90)
turtle.circle(-100, -90)
turtle.end_fill()
turtle.done()
#例题4输入一个数字,绘制以该数字为烂卖银边数的正多边形
import turtle
a=int(turtle.textinput("绘制正多边形","请输入边数:"))
turtle.circle(100,360,a)
turtle.done()