智启元队内比赛题目(一)

题B:输出第二个整数

源代码:

a, b, c = map(int, input().split())

print(b)

 主要要掌握的是map()函数的用法:

split() 的使用方法:

用split() 函数可以实现一行输入多个参数,并且参数之间以空格隔开,下面也有多道题目需要用到split()函数。

题C:对齐输出

源代码:

# 读取输入的三个整数
a, b, c = map(int, input().split())

# 按照格式要求右对齐输出三个整数
print(f'{a:8d} {b:8d} {c:8d}')

要掌握f-string的用法:

 理论上还可以用end=''不换行输出来实现

a,b,c = map(int,input().split())
print(a,end='        ')
print(b,end='        ')
print(c)

题G:温度表达转化

源代码:

a = float(input())
b = 5*(a-32)/9
print('%.5f'%b)

主要要掌握精确小数点后几位 '%.d' 的用法

题H:打印ASCII码

源代码:

# 读取输入的字符
char = input().strip()

# 输出字符的ASCII码
ascii_value = ord(char)
print(ascii_value)

 特别注意的点是,题中强调了输入除空格外的字符,因此要用到strip()函数的用法

题I:翻转输出一个三位数

源代码:采用字符串切片的做法

# 读取输入的三位数
num = input()

# 反向输出并保留前导零
reverse_num = num[::-1]
print(reverse_num)

还可以使用reversed()来实现上述功能,代码如下:

num = input()
print(''.join(reversed(num)))

题J:自动取款机

源代码:

a,b = map(int,input().split())
c = (a-b)//100 #得到的结果为整数(往小取值)
d = (a-b)%100 
if d != 0: #判断差是否刚好为100的倍数
    e=c+1
    print(e)
elif d==0:
    print(c)

题K:小杨做题

源代码:

# 读取输入的a, b, m, N
a = int(input())
b = int(input())
m = int(input())
N = int(input())

# 初始化小杨总题数和前两天的题数
total = a + b
prev_day1 = a
prev_day2 = b

# 从第3天开始计算每天的题数,直到第N天
for day in range(3, N+1):
    current_day = prev_day1 + prev_day2
    if current_day >= m:
        break
    total += current_day
    prev_day1, prev_day2 = prev_day2, current_day

print(total)

个人觉得没有其他问题,但是就是不完全对 

 题L:灵活控分

源代码:

import math
a = int(input())
b = a/10
x = math.pow(b,2)
print(math.ceil(x))

 主要要掌握math模块的运用:

 

 

  • 9
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值