Skip to content

编程题知识点

发布时间:

1.温度转换,涉及 字符型转浮点型、f格式化字符串方法

js
K = float( input() ) #'412.00'  412.00

C = K-273.15

F = C*1.8+32

if F>212:
    print('Temperature is too high!')
else:
    print(f"{C:.2f} {F:.2f}")
   

2.求奇偶数个数

涉及 利用for循环实现多行输入

js
n = int(input())
a = 0
b = 0
for i in range(n):
    x = int(input())
    if x%2 !=0:
        a+=1
    else:
        b+=1
print(a,b)