python 9.13作業

來源:互聯網
上載者:User

標籤:goto   同心圓   sha   tps   input   mon   org   三星   .com   

2-a 用迴圈畫五角星

import turtlefor i in range(5):    turtle.forward(200)    turtle.left(144)

 

2-b 用迴圈畫同心圓

import turtleturtle.color(‘red‘)for i in range(4):    turtle.up()    turtle.goto(0,-40*(i+1))    turtle.down()    turtle.circle(40*(i+1))

 

2-c 用while迴圈畫太陽花

from turtle import *color(‘red‘,‘yellow‘)begin_fill()while True:    forward(200)    left(170)    if abs(pos())<1:        breakend_fill()done()

2-d 用函數定義畫五個五角星

import turtleturtle.bgcolor(‘red‘)turtle.color(‘yellow‘)turtle.fillcolor(‘yellow‘)def guo_goto(x,y):        turtle.up()    turtle.goto(x,y)    turtle.down()def guo_draw(x):          turtle.begin_fill()    for i in range(5):        turtle.forward(x)        turtle.right(144)    turtle.end_fill()guo_goto(-300,200)    guo_draw(170)guo_goto(30,280)guo_draw(60)guo_goto(120,200)guo_draw(60)guo_goto(120,126)guo_draw(60)guo_goto(30,60)guo_draw(60)

2-e 用函數定義畫鑽石花瓣的太陽花

import turtledef draw_diamond(brad):    brad.forward(100)    brad.right(45)    brad.forward(100)    brad.right(135)def draw_art():    window=turtle.Screen()    window.bgcolor("purple")    brad=turtle.Turtle()    brad.shape("turtle")    brad.color("orange")    brad.speed("fastest")    for i in range(1,37):        draw_diamond(brad)        draw_diamond(brad)        brad.left(10)    brad.right(90)    brad.pensize(5)    brad.color(‘green‘)    brad.forward(300)    window.exitonclick()draw_art()

3-a 輸入學號,識別年級、專業、序號。

s=input("Please input your Student Number:")print("年級是",s[:4])print("專業是",s[4:6])print("序號是",s[-3:])

3-b 輸入1-7的數字,輸出對應的“星期幾”。

a=‘星期一星期二星期三星期四星期五星期六星期日‘d=int(input(‘1-7:‘))print(a[3*(d-1):3*d])

3-c 識別社會安全號碼中的省市區、年齡、性別。

ID=input(‘請輸入十八位社會安全號碼碼: ‘)if len(ID)==18:  print("你的社會安全號碼碼是 "+ID)else:  print("錯誤的社會安全號碼碼")  ID_add=ID[0:6]ID_birth=ID[6:10]ID_sex=ID[14:17]if int(ID_add)==440101:  print("省市區:廣東省廣州市市轄區")elif int(ID_add)==440102:    print("省市區:廣東省廣州市東山區")elif int(ID_add)==440103:    print("省市區:廣東省廣州市荔灣區")elif int(ID_add)==440104:    print("省市區:廣東省廣州市越秀區")elif int(ID_add)==440105:    print("省市區:廣東省廣州市海珠區")    birth=2017-int(ID_birth[0:4])print("年齡:{}".format(birth))   if int(ID_sex)%2==0:  print(‘性別:女‘)else:  print(‘性別:男‘)

3-d 用字串操作產生python文檔各庫的網址(起始網址在這裡https://docs.python.org/3.6/library/index.html)

3-e 練習字串的+,*,in,len(),eval()

 

python 9.13作業

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.