《python语言设计程序设计》_第一章编程题

2021-07-20 00:06

阅读:622

标签: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语言设计程序设计》_第一章编程题

标签:goto   pen   end   turtle   程序设计   imp   bsp   就会   不一致   

原文地址:https://www.cnblogs.com/qiyuanjiejie/p/9520310.html


评论


亲,登录后才可以留言!