1. 程式人生 > >實驗1 Python簡單程式設計

實驗1 Python簡單程式設計

a

1 sum = 0
2 n = eval(input())
3 
4 for i in range (1, n + 1):
5     sum += (1/i)*(-1)**(i+1)
6 
7 print(sum)

 

 

b

1 while True:
2     n = input()
3     if n[-1] == 'D':
4         m = eval(n[0:-1])
5         print("{}R".format(m*6.9))
6     else:
7         m = eval(n[0:-1])
8 print("{:.0f}D".format(m//6.9))

 

c

 1 while True:
 2     try:
 3         n = input()
 4         n = n.strip()//注意去掉空格
 5     except :
 6         exit(0)
 7     le = len(n)
 8     prime = True
 9     for i in range (0,le//2):
10         if n[i] != n[le - i - 1]:
11             prime = False
12 break; 13 if prime: 14 print("True") 15 else: 16 print("False")

 

d

1 import math
2 an = list(map(int, input().split(",")))
3 # print('''可以構成三角形,周長:12.0,面積:6.0''')
4 if an[0] + an[1] > an[2] and an[0] and an[1] and an[2]:
5     n = (an[0] + an[1] + an[2])/2
6
s = math.sqrt(n*(n - an[0])*(n - an[1])*(n - an[2])) 7 print("{:.1f},{:.1f}".format(an[0] + an[1] + an[2], s)) 8 else: 9 print("無法構成三角形!")