79(温故而知新)刷牛客遇到的一些题目
题目:输入:
3
2
输出:
1 1
1.50
x = 3
y = 2
# print(int(x / y), x % y)
print(x // y, x % y) # // 是Python中数学运算符: 整除(向小取整)
print(f'{x/y:.2f}')
def myfunc(n):
return len(n)
x = map(myfunc, ('apple', 'banana', 'cherry')) # 语法 map(function, iterables)
print(x) # <map object at 0x000001DA0E3EA630>
print(list(x)) # [5, 6, 6]
输入:
1 2 3 4
输出:
-3
x, y, z, k = map(int, input().split())
print((x + y) * (z - k)) # -3
a = map(int, input().split())
print(a) # <map object at 0x000002171F7073C8>
print(list(a)) # [1, 2, 3, 4]
my_list = []
if my_list:
print('my_list is not empty!')
else:
print('my_list is empty!')
在Python中,False,0,’’,[],{},()都可以视为假
dish = { 'pizza':10, 'rice':2, 'yogurt':5, 'others':8}
x= input()
if x not in dish.keys():
x = 'others' # 将没有的keys 都归到 others里
for i in dish.keys():
if i==x:
print(dish[i])
break
dic_1 = {'A':4.0, 'B':3.0, 'C':2.0, 'D':1.0, 'F':0}
sum1 = 0
sum2 = 0
while True:
x = input()
if x.lower() == 'false':
break
y = int(input())
sum1 += dic_1[x] * y
sum2 += y
print("%.2f" % (sum1 / sum2))
本文来自博客园,作者:__username,转载请注明原文链接:https://www.cnblogs.com/code3/p/17135870.html