简单判断
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
b = int(input())
p = int(input())
r = int(input())
t = int(input())
if p*r*t < b:
print("Enough bread")
if p*r*t == b:
print("Just enough bread")
if p*r*t > b:
print("Not enough bread")
计算2的幂总和
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = int(input())
# 计算2的幂总和
print(sum([2**i for i in range(n)]))
ascii求和
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
line = input()
sum_count = 0
for i in line:
# 计算ascii
sum_count += ord(i)
print(int(math.sqrt(sum_count)))
奇偶数索引
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = input()
ou_count = 0
ji_count = 0
for i , num in enumerate(n):
if int(num)%2==0:
ou_count += i
else:
ji_count += i
print(abs(ou_count - ji_count))
更优雅的写法(作者:norxondor_gorgonax)
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = input()
print(abs(sum(map(int, n[::2])) - sum(map(int, n[1::2]))))
大小写字母
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
s = input()
# 大写字母的数量
print(sum(1 for c in s if c.isupper()) ** sum(1 for c in s if c.islower()))
优雅写法(作者:norxondor_gorgonax)
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
s = input()
# Write an answer using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)
print(sum(map(str.isupper, s)) ** sum(map(str.islower, s)))
两数互质
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
a = int(input())
b = int(input())
# 给定两个整数 a 和 b。对于这两个整数,我们寻找能除以 a 和 b 的正整数(不留余数)。如果除了 1 之外不存在这样的整数,我们称 a 和 b 互质。
print('true' if math.gcd(a, b) == 1 else 'false')
优雅(作者:norxondor_gorgonax)
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
a = int(input())
b = int(input())
# Write an answer using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)
print(str(math.gcd(a,b)==1).lower())
chr
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = int(input())
# 1对应A,拿到对应字符
print(chr(64 + n)*n)
这里注意chr
是 Python 中的一个内置函数,用于将一个整数(通常是一个 Unicode 码点)转换为其对应的字符