发布时间:2023-07-02 14:00
for i in range(999, -1, -1):
if i % 5 == 0:
if i % 7 == 0:
print(\"小于1000的所有整数中能够同时被5和7整除的最大整数为:\", i)
break
total = 0
for i in range(101):
total += i
print(\"1+2+。。。+100 = \", total)
import math
print(\"100以内的素数包括:\")
for i in range(2, 100):
limit = int(math.sqrt(i))
for j in range(2, limit + 2):
if j == limit + 1:
print(i, end=\" \")
if i % j == 0:
break
import random
choose = int(input(\"请选择抓狐狸的洞口编号:\"))
pos = random.randint(0, 4)
while choose != pos:
print(\"未抓到狐狸,狐狸在{}号洞口\".format(pos))
choose = int(input(\"请重新选择洞口编号:\"))
if pos == 0:
pos += 1
elif pos == 4:
pos -= 1
else:
pos += random.sample([1, -1], 1)[0]
print(\"恭喜你,你在{}号洞口抓到了狐狸\".format(pos))
print(\"可能的购买组合有:\")
flag = 0
for i in range(7):
for j in range(51):
for k in range(21):
if i*15 + j*2 + k*5 == 100:
flag += 1
print(\"{:2}瓶洗发水,{:2}盒香皂,{:2}支牙刷\".format(i, j, k), end=\" \")
if flag % 4 == 0:
print(\"\")
def GCD(a, b):
while a % b != 0:
temp = b
b = a % b
a = temp
return b
num = input(\"请输入两个整数(空格分隔):\")
a, b = (eval(i) for i in num.split(\" \"))
gcd = GCD(a, b)
lcm = a * b // gcd
print(\"{}和{}的最大公约数为{},最小公倍数为{}\".format(a, b, gcd, lcm))
total = 0
for i in range(1, 10, 2):
mul = 1
for j in range(1, i+1):
mul *= j
total += mul
print(\"1!+3!+5!+7!+9! =\", total)
num = int(input(\"请输入一个整数:\"))
if num > 0:
print(1)
elif num < 0:
print(-1)
else:
print(0)
string = input(\"请输入一行字符:\")
letter = digit = space = other = 0
for char in string:
if char.isalpha():
letter += 1
elif char.isalnum():
digit += 1
elif char.isspace():
space += 1
else:
other += 1
print(\"字符串中有{}个字母,{}个数字,{}个空格,{}个其他字\"
\"符\".format(letter, digit, space, other))
price = eval(input(\"请输入购物款数:\"))
if price >= 5000:
preferencial_price = price * 0.8
elif price >= 3000:
preferencial_price = price * 0.85
elif price >= 2000:
preferencial_price = price * 0.9
elif price >= 1000:
preferencial_price = price * 0.95
else:
preferencial_price = price
print(\"最终价格为:\", preferencial_price)
本次实验中的大部分内容相对简单,题目类型在其他计算机语言的学习中也较为常见。对于新手学习python编程,这是一些不错的题型,同时有其他语言编程基础的人也能较为方便地区分与之前所学语言的区别。