python语言程序设计编程题_《python语言程序设计》_第一章编程题
題目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语言程序设计编程题_《python语言程序设计》_第一章编程题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: a*算法流程图_学好流程控制结构轻松应对
- 下一篇: python类方法继承_对python中