第一章
?
第一题
a = int(input())
b = int(input())
print(a+b)
第二题
a = int(input())
b = int(input())
c = int(input())
print(b*b-4*a*c)
第三题
print("Python语言简单易学")
第二章
?
第一题
sum = 0
n = int(input())
for i in range(1, n+1):
sum += i
print(sum)
第二题
x = float(input())
if x == 0:
print("f(%.1f)=0.0" % x)
else:
print("f(%.1f)=%.1f" % (x, (1/x)))
第三题
cost = float(input())
if cost < 0:
print("Invalid Value!")
elif cost <= 50:
print("cost=%d" % (cost*0.53))
else:
print("cost=%d" % (50*0.53 + (cost-50)*(0.53+0.05)))
第四题
a = input()
n = int(input())
print("s = %d" % (sum([int(a*i) for i in range(1, n+1)])))
第五题
sum = 0
a = input()
for i in a.split(' '):
if int(i) <= 0:
break
if int(i) % 2 != 0:
sum += int(i)
print(sum)
第六题
n = int(input())
sum = 0
flag = 1
m = 1
for i in range(1, n+1):
if flag == 1:
sum += i / m
else:
sum -= i / m
m += 2
flag *= -1
print("%.3f" % sum)
第三章
?
第一题
a = input()
s = sum(int(i) for i in a.split())
s /= len(a.split())
for i in a.split(' '):
if int(i) > s:
print("%d " % int(i), end='')
第二题
a = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
m = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
q = input()
sum = 0
for i in range(0, len(q)-1):
sum += a[int(q[i])]
z = m[sum%11]
if z == q[len(q)-1]:
print('yes')
else:
print('no')
第四章
?
第一题
for i in range(1,6):
print('*'*i)
for i in range(1,6):
print(' '*(5-i),end='')
print('*'*(2*i-1))
for i in range(1,4):
print(' '*(3-i),end='')
print('*'*(2*i-1))
for i in range(2,0,-1):
print(' ' * (3-i), end='')
print('*' * (2 * i - 1))
第二题
a = list(range(1,31))
k = 1
flag = 0
x = 0
while flag != 10:
if x >= len(a):
x = x - len(a)
if k == 9:
flag += 1
print(a.pop(x),end=' ')
k = 1
k += 1
x += 1
第三题
def a(i):
sum = 0
for j in range(1,i):
if i % j ==0:
sum += j
if sum == i:
return True
else:
return False
for i in range(6,1000):
if a(i):
print(i,end=' ')
第四题
import math
def s(a):
i = 2
while i <= math.sqrt(a):
if a % i ==0:
return 0
i += 1
return a
sum1 = 0
for i in range(101,1000,2):
sum1 += s(i)
print(sum1)
第五题
第六题
第七题
|