- 博客(6)
- 收藏
- 关注
原创 python使用字典来随机统计列表中水果出现的次数
1.定义一组水果2.随机100次,每次随机选择一种水果3.使用字典来统计每个水果出现的次数import randomfruits = ['香蕉', '草莓', '苹果', '梨子', '西瓜', '芒果', '葡萄']fruits_dict = {} # 定义一个空字典count = 0 # 计数while count < 100: fruit = random.choice(fruits) # 随机选择一种水果 if fruit in fruits_
2022-04-04 14:05:48
6179
1
原创 python判断身份证真伪
Factor = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)Last = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2')Last_dict = {}sum = 0idcard = input("请输入身份证号码:")if len(idcard) == 18: # 判断身份证号码是否输入正确 for i in range(0, .
2022-04-02 22:29:25
2658
原创 C语言定义一个函数,判断x是否为回文数
设n是一任意自然数。若将n的各位数字反向排列所得自然数n1与n相等,则称n为一回文数。例如,若n=1234321,则称n为一回文数;但若n=1234567,则n不是回文数。[百度资料]代码如下:#include<stdio.h>int f(int x){ int a,b = 0; //定义两个变量,并给b赋值为0; a = x; //将x的值赋值给a; while (x != 0) { b = b * 10 + x % 10
2021-12-05 13:58:54
6347
1
原创 C语言函数调用:编写一个判断是否为闰年的函数
#include<stdio.h>int f(int year){ if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 1; else return 0;}void main(){ int year; printf("请输入年份year:\n"); scanf("%d", &year); if (f(ye
2021-11-30 19:23:14
3127
原创 C语言:递归求x的n次方
#include<stdio.h>int f(int x, int n){ if (n < 2) return x; return x * f(x, n - 1);}void main(){ int x,n; printf("请输入x、n的值:\n"); scanf("%d%d", &x, &n); printf("%d\n", f(x, n));}
2021-11-29 12:19:05
6407
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人