-
peng111说:
对tuple_01=(34,23,63,7,45)元组进行升序排序,不使用sort函数
§ Code
tuple_01 = (34,23,63,7,45)
list_01 = list(tuple_01)
list_01.sort()tuple_01 = tuple(list_01)
print(tuple_01)§ Output
stdout : ['(7, 23, 34, 45, 63)\n']
§ Markdown
3
使用一行代码实现统计tuple_02=(2,3,5,7,9,3,5,7)中每个元素出现的次数
§ Code
tuple_02 = (2, 3, 5, 7, 9, 3, 5, 7)
dict_01 = dict.fromkeys(tuple_02, 0)
for i in tuple_02:
dict_01[i] += 1
print(dict_01)§ Output
stdout : ['{2: 1, 3: 2, 5: 2, 7: 2, 9: 1}\n']
§ END OF DOC
-
peng111说:
编写一程序,其向D盘下的文件“test.txt”中写入本人姓名,班级编写一程序,其向D盘下的文件“test.txt”中写入本人姓名,班级
#include
int main()
{
FILE *fp;
char name[] = "张三";
char class[] = "计算机1701班";
fp = fopen("D:\test.txt", "w"); // 打开文件
if (fp == NULL)
{
printf("无法打开文件!");
return -1;
}
else
{
fprintf(fp, "姓名:%s\n", name);
fprintf(fp, "班级:%s\n", class);
printf("写入成功!\n");
}
fclose(fp); // 关闭文件
return 0;
}