一、认识Python
生活随笔
收集整理的這篇文章主要介紹了
一、认识Python
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.Hello World~!
>>> print("Hello World~!") Hello World~!2.簡單交互(交互式,文件式)
>>> name=input("輸入姓名:") 輸入姓名:kok >>> print("{}先生,你好。".format(name)) kok先生,你好。3.用戶輸入兩個數(shù)字,計算兩數(shù)之和
>>> n1=input('n1=') n1=123 >>> n2=input('n2=') n2=456 >>> n1+n2 '123456' >>> float(n1)+float(n2) 579.04.輸入三角形三邊長度,求三角形面積(海倫公式)
>>> a=float(input("a="))a=10
>>> b=float(input("b="))
b=8
>>> c=float(input("c="))
c=6
>>> p=(a+b+c)*0.5
>>> print(p)
12.0
>>> S=(p*(p-a)*(p-b)*(p-c))**0.5
>>> print("三角形面積為{}")
三角形面積為{}
>>>? print("三角形面積為{}".format(S))
?
SyntaxError: unexpected indent
>>> print(S)
24.0
>>>
不理解為什么不能整體解釋:
?
5.輸入半徑,求圓面積
>>> r=10 >>> Sc=r*r*3.14159265 >>> print('Sc') Sc >>> print(Sc) 314.1592656.一行代碼完成計算兩數(shù)之和
>>> print("T=:%.2f"%(float(input('n1='))+float(input('n2=')))) n1=10 n2=20 T=:30.007.畫一組同切圓
import turtle turtle.pensize(2) turtle.circle(10) turtle.circle(40) turtle.circle(80) turtle.circle(140)8.繪制五角星(縮進-即空4格,代表該代碼屬于循環(huán)內(nèi))
import turtleturtle.bgcolor("red") //背景色 turtle.fillcolor("yellow") //填充顏色 turtle.color('yellow')//線條顏色 turtle.begin_fill() for i in range (5):turtle.forward(200)turtle.right(144)turtle.end_fill()9.畫一組同心圓。
import turtle #第一個圓形 turtle.penup() turtle.goto(0,-150) turtle.pendown() turtle.circle(150) #第二個圓形 turtle.penup() turtle.goto(0,-50) turtle.pendown() turtle.circle(50) #第三個圓形 turtle.penup() turtle.goto(0,-100) turtle.pendown() turtle.circle(100)?
轉(zhuǎn)載于:https://www.cnblogs.com/maykok/p/7483889.html
總結(jié)
以上是生活随笔為你收集整理的一、认识Python的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转载]Java数据库设计中的14个技巧
- 下一篇: 宁波深化智慧城市建设开启智能交通新模式