L1-001Hello World!
print("Hello World!")
L1-002 打印沙漏
import math
n, c = input().split()
n = int(n)
h = int(math.sqrt((n + 1) // 2))
# 打印上半层沙漏
for i in range(h):
print(" " * i + c * (2 * (h - i) - 1))
# 打印下半层沙漏
for i in range(2, h + 1):
print(" " * (h - i) + c * (2 * i - 1))
remaining_symbols = n - 2 * h * h + 1
print(remaining_symbols)
L1-003 个位数统计
s = input()
a = [0] * 10
for char in s:
digit = int(char)
a[digit] += 1
for i in range(10):
if a[i] != 0:
print(f"{i}:{a[i]}")
L1-004 计算摄氏温度
f = int(input())
celsius = 5 * (f - 32) / 9
print("Celsius =", int(celsius))
L1-005 考试座位号
N=int(input())
a=[]
b=[]
c=[]
for i in range(N):
t=input().split()
a.append(t[0])
b.append(int(t[1])) #因为我们要查询它在列表中位置,所以得用int()
c.append(t[2])
t=int(input())
d=input().split()
for i in d:
t=b.index(int(i)) #通过index()方法找到位置
print(a[t],c[t])
L1-006 连续因子
import math
n = int(input())
m = 0
mm = -1
for i in range(2, int(math.sqrt(n))+1):
if n % i == 0:
j = i + 1
t = n / i
while t % j == 0:
t = t / j
j = j + 1
if j - i > m:
m = j - i
mm = i
if mm != -1: # 可能有质数的情况
print(m)
s = str(mm)
for i in range(mm + 1, mm + m):
s = s + "*" + str(i)
print(s)
else:
print(1)
print(n)
L1-007 念数字
dict={'-':'fu','0':'ling','1':'yi','2':'er','3':'san','4':'si','5':'wu',
'6':'liu','7':'qi','8':'ba','9':'jiu'}
a=input()
for i in range(len(a)-1):
print(dict[a[i]],end=" ")
print(dict[a[len(a)-1]])
L1-008 求整数段和
a=input().split()
sum=0
cnt=0
for i in range(int(a[0]),int(a[1])+1):
sum=int(i)+sum
if cnt%5==0 and cnt!=0 :
print()
print("%5d"%i,end="")
cnt=cnt+1
print("\nSum = %d"%sum)
L1-009 N个数求和
# 又是为大数舒服的一题
def gcd(a, b):
while b != 0:
c = a % b
a = b
b = c
return a
n = int(input())
s = input().split()
mu = 1
for i in s:
i = i.split("/")
mu = mu * int(i[1])
zi = 0
for i in s:
i = i.split("/")
zi = zi + int(i[0]) * mu // int(i[1])
t = gcd(abs(zi), mu)
zi = zi // t
mu = mu // t
if zi == 0: # 为零的情况,测试点6
print(0)
flag = False
if abs(zi) >= mu: # 分子为负数的情况,测试点4.5
print(zi//mu, end="")
flag = True
if abs(zi)%mu != 0:
if flag:
print(end=" ")
if zi < 0:
print(end="-")
zi = abs(zi)
print(zi%mu, mu,sep="/")
L1-010 比较大小
a=input().split()
b=[]
for i in a:
b.append(int(i))
b.sort()
for i in b[0:len(b)-1]:
print(i,end="->")
print(b[len(b)-1])