input键盘输入一串字符,分别统计其中数字字符shu、英文字母ying、其他字符的个数qita。(是否数字可以使用isdigit,是否英文字母使用isalpha) a=input("请输入一串字符,要求含有字母数字和其他符号:")
时间: 2023-05-31 08:04:33 浏览: 159
shu = 0
ying = 0
qita = 0
for i in a:
if i.isdigit():
shu += 1
elif i.isalpha():
ying += 1
else:
qita += 1
print("数字个数为:", shu)
print("英文字母个数为:", ying)
print("其他字符个数为:", qita)
相关问题
<tr> <th>学历:</th> <td><input type="radio" name="zhuanke" id="" value="one" checked>专科 <input type="radio" name="benke" id="" value="two">本科 <input type="radio" name="benshuo" id="" value="three">本硕研究生 <input type="radio" name="boshi" id="" value="four">博士研究生 <input type="radio" name="qita" id="" value="five">其他</td> </tr>为什么这一段代码出来的radio组件点击选择后不能做到单选框的效果
这个代码中的radio组件之间没有相同的name属性,因此它们无法彼此排斥,就会出现多选的情况。需要给这些radio组件设置相同的name属性,这样它们就可以实现单选框的效果了。例如:
```
<tr>
<th>学历:</th>
<td>
<input type="radio" name="xueli" id="" value="one" checked>专科
<input type="radio" name="xueli" id="" value="two">本科
<input type="radio" name="xueli" id="" value="three">本硕研究生
<input type="radio" name="xueli" id="" value="four">博士研究生
<input type="radio" name="xueli" id="" value="five">其他
</td>
</tr>
```
在上面的代码中,每个radio组件都有相同的name属性值:xueli。这样就可以保证它们之间互相排斥,实现单选框的效果。
c++题目描述 定义一个记录类型,它的每个值表示X-Y坐标上的一个点,X,Y的取值范围是0到100之间的整数。编一程序,顺时针读入一个四边形的各点a,b,c,d的X-Y值,并判断它是否能构成正方形(Zhengfangxing)、矩形(Juxing)或者其它四边形(Qita)。 输入 见上面 输出 见上面 样例 输入 复制 1 1 0 1 0 0 1 0 输出 复制 Zhengfangxing
你可以使用 C++ 来解决这个问题。以下是一个示例代码:
```cpp
#include <iostream>
#include <cmath>
// 定义一个记录类型表示点
struct Point {
int x;
int y;
};
// 计算两点之间的距离
double distance(Point p1, Point p2) {
int dx = p2.x - p1.x;
int dy = p2.y - p1.y;
return std::sqrt(dx * dx + dy * dy);
}
// 判断四边形是否为正方形
bool isSquare(Point a, Point b, Point c, Point d) {
double ab = distance(a, b);
double bc = distance(b, c);
double cd = distance(c, d);
double da = distance(d, a);
// 判断对角线是否相等且边长相等
if (ab == bc && bc == cd && cd == da && ab == da) {
return true;
}
return false;
}
// 判断四边形是否为矩形
bool isRectangle(Point a, Point b, Point c, Point d) {
double ab = distance(a, b);
double bc = distance(b, c);
double cd = distance(c, d);
double da = distance(d, a);
// 判断对角线是否相等且边长成对相等
if (ab == cd && bc == da) {
return true;
}
return false;
}
int main() {
Point a, b, c, d;
// 顺时针读入四边形的各点坐标
std::cin >> a.x >> a.y;
std::cin >> b.x >> b.y;
std::cin >> c.x >> c.y;
std::cin >> d.x >> d.y;
// 判断四边形的类型并输出结果
if (isSquare(a, b, c, d)) {
std::cout << "Zhengfangxing" << std::endl;
} else if (isRectangle(a, b, c, d)) {
std::cout << "Juxing" << std::endl;
} else {
std::cout << "Qita" << std::endl;
}
return 0;
}
```
你可以将上述代码保存为一个 C++ 文件,例如 `quadrilateral.cpp`,然后使用 C++ 编译器进行编译和运行。在命令行中运行以下命令:
```
g++ quadrilateral.cpp -o quadrilateral
./quadrilateral
```
然后按照提示顺时针输入四边形的各点坐标,程序将输出四边形的类型。在给定的样例输入中,程序将输出 "Zhengfangxing"。
阅读全文
相关推荐
















