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

Posted SUMIKO

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了《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第一章 程序设计语言

现代软件工程 第一章 概论 第4题——邓琨

第一章 Python入门

尚学堂__百战程序员__1573题------第一章 初始java

第一章 Python基础

PTA 程序设计题(数据结构第一章)