《python語言設計程式設計》_第一章編程題

來源:互聯網
上載者:User

標籤:goto   pen   end   turtle   程式設計   imp   bsp   就會   不一致   

題目1.1 :顯示"welcome to python "

答案:print(‘welcome to python‘)

題目1.2:顯示"welcome to python " 五次

答案:print ("welcome to python\n") * 5  #\n表示換行,要是沒有\n的話就會串連在一起

題目1.3:編寫fun,其中fun是分別有fun組成。

答案:#注意,"N","N"和”NN"長度不一致

print ("F"*7," "*3,"U"," "*5,"U"," "*3,"N"*2," "*4,"N"*2)
print ("F"*2," "*4," "*3,"U"," "*5,"U"," "*3,"N"*3," "*3,"N"*2)
print ("F"*7," "*3,"U"," "*5,"U"," "*3,"N"*2,"","N"*1," "*1,"N"*2)
print ("F"*2," "*4," "*3,"","U"," "*3,"U"," "*4,"N"*2," "*2,"N","N"*2)
print ("F"*2," "*4," "*5,""*3,"U"*3," "*2," "*3,"N"*2," "*3,"N"*3)

 題目1.4:編寫程式顯示下面的表格(類似矩陣)

答案:#二位元和兩位元的長度不一樣,要根據資料的長度調整空格的長度

value= [1,2,3,4]
print ("a", " "*2, "a^2"," "*2,"a^3"," "*4,)
print ("1", " "*2, "1"," "*5,"1"," "*4)
print ("3", " "*2, "9"," "*5,"27"," "*4)
print ("4", " "*2, "16"," "*4,"64"," "*4)

題目:1.5編寫程式顯示下面運算式的結果:(9.5*4.5-2.5*3)/(45.5-3.5)

答案:print((9.5*4.5-2.5*3)/(45.5-3.5))

要是加上雙引號,即:

print("(9.5*4.5-2.5*3)/(45.5-3.5)")

那顯示的是這個公式(9.5*4.5-2.5*3)/(45.5-3.5)

題目1.6 :級數求和,編寫程式顯示1+2+3+4+5+6+7+8+9的和

答案:  #for之後那一列(可能是幾列)要縮排

sum = 0   

for i in range(10) 

  sum+=i 

print ( sum) 

題目1.7 :(近似Π)可以使用下面的公式計算Π=4*(1-1/3+1/5-1/7+1/9-1/11+...),編寫程式顯示4*(1-1/3+1/5-1/7+1/9-1/11)和4*(1-1/3+1/5-1/7+1/9-1/11+1/13-1/15)

答案:#**表示次方

程式1:

pi = 0.0
for i in range(1,6):
pi += 4*(((-1)**(i+1))/(2*i-1))
print (pi)

程式2:

pi = 0.0
for i in range(1,8):
pi += 4*(((-1)**(i+1))/(2*i-1)) 
print (pi)

 1.8

顯示r=5.5的圓的面積和周長。

1.9;1.10;1.11不會

1.12

程式:#求更加簡單的分享

import turtle
turtle.forward(100)

turtle.right(90)
turtle.forward(100)

turtle.right(90)
turtle.forward(200)

turtle.right(90)
turtle.forward(200)

turtle.right(90)
turtle.forward(200)

turtle.right(90)
turtle.forward(100)

turtle.right(90)
turtle.forward(200)


turtle.left(90)
turtle.forward(100)

turtle.left(90)
turtle.forward(100)

turtle.left(90)
turtle.forward(200)

turtle.left(180)
turtle.forward(100)

 

 

程式2:

import turtle
turtle.penup()
turtle.goto(-50,0)
turtle.pendown()
turtle.forward(100)
turtle.penup()
turtle.goto(0,50)
turtle.right(90)
turtle.pendown()
turtle.forward(100)

程式3:#注意轉折處的角度

import turtle
turtle.right(60)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)

 

程式4:

import turtle
turtle.right(60)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.right(120)
turtle.forward(200)
turtle.left(120)
turtle.forward(100)
turtle.left(120)
turtle.forward(100)

 

 

 好無聊,改天再畫

 

《python語言設計程式設計》_第一章編程題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.