zoukankan      html  css  js  c++  java
  • 《python语言程序设计》_第一章编程题

    题目1.1 :显示"welcome to python "

    答案:print('welcome to python')

    题目1.2:显示"welcome to python " 五次

    答案:print ("welcome to python ") * 5  # 表示换行,要是没有 的话就会连接在一起

    题目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)

     好无聊,改天再画

  • 相关阅读:
    esayui session 超时跳转登录页面
    jQuery easyui dataGrid checkbox反显的值取不到
    SAP中Search help的使用
    ABAP数据表的操作
    ABAP怎样提高代码执行效率?
    实战屏幕SCREEN总结
    SAP窗口基本点
    单选按钮实现alv格式显示和报表下载功能
    JSON字符串转List对象
    XML解析
  • 原文地址:https://www.cnblogs.com/qiyuanjiejie/p/9520310.html
Copyright © 2011-2022 走看看