Python3從零學習(六)
阿新 • • 發佈:2018-11-05
# -*- coding:utf-8 -*-
year =int(input("請輸入一個年份:"))
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("是閏年")
else:
print("不是閏年")
else:
print("不是閏年")
else:
print("不是閏年")
celsius = float(input("請輸入攝氏溫度:")) fahrenheit = (celsius * 1.8) + 32 print("{}攝氏溫度轉華氏溫度為:{}".format(celsius,fahrenheit)) celsius = (fahrenheit - 32) / 1.8 print("{}華氏溫度轉攝氏溫度為:{}".format(fahrenheit,celsius))
a = float(input("請輸入邊長a:"))
b = float(input("請輸入邊長b:"))
c = float(input("請輸入邊長c:"))
while (abs(a - b) >= c or c >= abs(a + b)):
c = float(input("請輸入邊長c:"))
s = (a + b + c) / 2
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print("三角形的面積為:{}".format(area))
import cmath a = float(input("輸入a:")) b = float(input("輸入b:")) c = float(input("輸入c:")) d = (b**2) - (4 * b * c) sol1 = (-b-cmath.sqrt(b))/(2*a) sol2 = (-b+cmath.sqrt(b))/(2*a) print("結果為:{}和{}".format(sol1,sol2))