Python輸入輸出練習,運算練習,turtle初步練習

來源:互聯網
上載者:User

標籤:fill   輸入輸出   實現   結果   images   互動式   教材   begin   面積   

題目:

Hello World!
簡單互動(互動式,檔案式)教材P19
使用者輸入兩個數字,計算並輸出兩個數字之和(嘗試用一行代碼實現)。
使用者輸入三角形三邊長度,並計算三角形的面積:(海倫公式)
輸入半徑,計算圓的面積。
畫一組同切圓
畫一個五角星
畫一個全黃色的五角星

1、Hello world!

>>> print(‘Hello world!‘)Hello world!

 

2、簡單互動

name = input("輸入姓名:")print("{}同學,學好python,前途無量!".format(name))print("{}大俠,學好python,前途無量!".format(name[0]))print("{}哥哥,學好python,前途無量!".format(name[1:]))

      結果:

 

 

3、簡單計算

n1 = input(‘請輸入第一個數字:‘)n2 = input(‘請輸入第二個數字:‘)sum = int(n1)+int(n2)print("sum=%d"%(sum))

     結果:

     使用一行代碼:

print(‘兩個數的和是%.2f‘%(float(input(‘請輸入第一個數字:‘))+float(input(‘請輸入第二個數字:‘))))

     結果:

 

4、計算三角形的面積

l1 = float(input(‘請輸入第一條邊的長度:‘))l2 = float(input(‘請輸入第二條邊的長度:‘))l3 = float(input(‘請輸入第三條邊的長度:‘))p = (l1+l2+l3) / 2s = (p*(p-l1)*(p-l2)*(p-l3))**0.5print(‘三角形的面積為:%.2f‘%s)

     結果:

 

5、計算圓的面積

r = float(input(‘請輸入圓的半徑:‘))s = r**2*3.14print(‘圓的面積為:%.2f‘%s)

     結果:

 

 

6、畫一組同切圓

import turtleturtle.circle(50)turtle.circle(100)turtle.circle(150)turtle.circle(200)

     結果:

 

7、畫一個五角星

import turtleturtle.forward(200)turtle.right(144)turtle.forward(200)turtle.right(144)turtle.forward(200)turtle.right(144)turtle.forward(200)turtle.right(144)turtle.forward(200)

     結果:

 

8、畫一個全黃色的五角星

import turtleturtle.color(‘yellow‘)turtle.fillcolor(‘yellow‘)turtle.begin_fill()turtle.forward(200)turtle.right(144)turtle.forward(200)turtle.right(144)turtle.forward(200)turtle.right(144)turtle.forward(200)turtle.right(144)turtle.forward(200)turtle.end_fill()

     結果:

 

Python輸入輸出練習,運算練習,turtle初步練習

聯繫我們

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