Ⅰ 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()