1.

1
2
3
4
5
6
7
arr = [0] * 110
nums = list(map(int, input().split()))
for i in nums:
arr[i] += 1
for i in range(1, 101):
if arr[i]:
print(f"{i}出现{arr[i]}次")

2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
nums = list(map(int, input().split()))
sum = 0.0
for i in nums:
sum += i
ans1 = 0
ans2 = 0
stand = sum/len(nums)
for i in nums:
if i > stand:
ans1 += 1
elif i < stand:
ans2 += 1
print("bigger:"+str(ans1))
print("smaller:"+str(ans2))

3

1
2
3
4
5
6
7
8
9
10
11
12
import random

def shuffle(lst):
result = []
while lst:
i = random.randrange(len(lst))
result.append(lst.pop(i))
return result

s = input("请输入数字列表,以空格分隔:")
lst = [int(i) for i in s.split()]
print("洗牌后的数字列表:", shuffle(lst))

4

1
2
3
4
5
a, b, c = map(int, input().split())
list = [a,b,c]
list.sort()
print(list)

5

1
2
3
4
5
6
7
8
9
10
11
12
13
a = int(input("Enter an integer:"))
if a % 5 == 0 and a % 6 == 0:
print("Is 10 divisible by 5 and 6? True")
else:
print("Is 10 divisible by 5 and 6? False")
if a % 5 == 0 or a % 6 == 0:
print("Is 10 divisible by 5 or 6? True")
else:
print("Is 10 divisible by 5 or 6? False")
if (a % 5 == 0 or a % 6 == 0) and not (a % 5 == 0 and a % 6 == 0):
print("Is 10 divisible by 5 or 6, but not both? True")
else:
print("Is 10 divisible by 5 or 6, but not both? False")

6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import random

lottery = random.randint(100, 999)
user_num = int(input("请输入一个三位数:"))

if user_num == lottery:
print(f"恭喜你,你中了$10,000,彩票号码是{lottery}。")
else:
lot_digits = [lottery // 100, (lottery // 10) % 10, lottery % 10]
user_digits = [user_num // 100, (user_num // 10) % 10, user_num % 10]
same = [d for d in user_digits if d in lot_digits]
if len(same) == 3:
print(f"恭喜你,你中了$3,000,彩票号码是{lottery}。")
else:
match_count = sum(1 for d in user_digits if d in lot_digits)
if match_count > 0:
print(f"恭喜你,你中了$1,000,彩票号码是{lottery}。")
else:
print(f"很遗憾,你没有中奖。彩票号码是{lottery}。")

7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def to_hex():
while True:
try:
value = int(input("请输入一个整数: "))
if value < 10:
print("十六进制是:"+str(value))
elif 10 <= value <= 15:
print("十六进制是:"+str((chr(ord('A') + value - 10))))
except ValueError:
print("无效输入,请输入一个整数。")


to_hex()

8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import random


def game():
user_choice = int(input("剪刀(0)、石头(1)、布(2):"))
computer_choice = random.randint(0, 2)
if user_choice == computer_choice:
print("平局。")
elif (user_choice == 0 and computer_choice == 1) or \
(user_choice == 1 and computer_choice == 2) or \
(user_choice == 2 and computer_choice == 0):
print("你赢了。")
else:
print("你输了。")


game()