这个是别人问我的,代码报错了,原来长这样
girl=3
count=0
while count<3:
a=input("how old is girl:")
if agirl:
print("猜大了")
else:
print("算你聪明")
break
count+=1
if count>=3:
b=input("是否继续:")
if b in("是,yes,Yes"):
count=o
else:
print("再见")
解决方案
1、python写的
girl=3
count=0
while count<3:
count+=1#把count++放到循环里面
a=int(input("how old is girl:"))#input获得的是str类型,不能直接和int比较,在前面加int()
if agirl:#输入的数大于3
print("猜大了")
else:
print("算你聪明")
break
if count>=3:#同↑
b=input("是否继续:")
if b in ['是','yes','Yes']:#in、not in检查特定值是否在列表中,是列表,你之前用的是字符串,也能运行,但是相当于b只要等于“是、y、e、s、Y、,”中任意组成的东西,等式都成立
count=0
else:
print("再见")
2、用C++改写(非本人写)
#include#include using namespace std; int main() { int girl = 3; int a; cout << "how old the girl" << endl; A: for (int i = 0;i < 3;i++) { cin >> a; if (a < girl) { cout << "猜小了" << endl; } else if (a > girl) { cout << "猜大了" << endl; } else { cout << "算你聪明" << endl; return 0; } } cout << "是否继续:" << endl; char n[100]; cin >> n; if (getchar() == 'y' || !((strcmp(n, "yes"))) || !((strcmp(n, "YES"))) || !((strcmp(n, "是")))) { goto A; } else cout << "再见" << endl; }



