酷代码 AI
菜单

有一天小明说脏话时被老师听到了,结果被罚在黑板上写 n n 遍"I don't say swear words!"。 输入格式 输入只有一行,其中含有一个正整数 n n( 1 ≤ n ≤ 10 1≤n≤10),代表被罚写的次数。 输出格式 输出 n n 行"I don't say swear words!"。

以下是使用Python语言实现的代码: ```python # 获取用户输入的正整数n n = int(input()) # 循环n次 for i in range(n): # 输出指定字符串 print("I don't say swear words!") ``` 代码解释: 1. `n = int(input())`:获取用户输入的一个正整数`n`,表示被罚写的次数。 2. `for i in range(n)`:使用`for`循环,循环`n`次。`range(n)`会生成一个从0到`n - 1`的整数序列。 3. `print("I don't say swear words!")`:在每次循环中,输出字符串`"I don't say swear words!"`。这样就会输出`n`行该字符串。 [2026-01-21 10:01:18 | AI问答 | 183点数解答]

服务商
相关提问
发财导航,免费问AI
实用工具查看更多