c语言转python急急急 255
#include<stdio.h>#include<stdlib.h>#include<math.h>intinput(intt);intcopu(ints);intma...
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int input(int t);
int copu(int s);
int main()
{
int tol = 0;
printf("\n* * * * * * * *Grab Fifty* * * * * * * \n");
printf("Game Begin\n");
rand();
if (rand() % 2)
tol = input(tol);
while (tol != 50)
if ((tol = copu(tol)) == 50)
printf("You Lose! \n");
else
if ((tol = input(tol)) == 50)
printf("You Win! \n");
printf(" * * * * * * * *Game Over * * * * * * * *\n");
return 0;
}
int input(int t)
{
int a;
do {
printf("Please count:");
scanf_s("%d", &a);
if (a > 2 || a < 1 || t + a>50)
printf("Error input,Try again!");
else
printf("You count:%d\n", t + a);
} while (a > 2 || a < 1 || t + a>50);
return t + a;
}
int copu(int s)
{
int c;
printf("Computer count:");
if ((s + 1) % 3 == 0)
printf(" %d\n", ++s);
else
if ((s + 2) % 3 == 0)
{
s += 2;
printf(" %d\n", s);
}
else
{
c = rand() % 2 + 1;
s += c;
printf(" %d\n", s);
}
return s;
}
简单代码谁数到50谁就赢的代码,可以任意改 展开
#include<stdlib.h>
#include<math.h>
int input(int t);
int copu(int s);
int main()
{
int tol = 0;
printf("\n* * * * * * * *Grab Fifty* * * * * * * \n");
printf("Game Begin\n");
rand();
if (rand() % 2)
tol = input(tol);
while (tol != 50)
if ((tol = copu(tol)) == 50)
printf("You Lose! \n");
else
if ((tol = input(tol)) == 50)
printf("You Win! \n");
printf(" * * * * * * * *Game Over * * * * * * * *\n");
return 0;
}
int input(int t)
{
int a;
do {
printf("Please count:");
scanf_s("%d", &a);
if (a > 2 || a < 1 || t + a>50)
printf("Error input,Try again!");
else
printf("You count:%d\n", t + a);
} while (a > 2 || a < 1 || t + a>50);
return t + a;
}
int copu(int s)
{
int c;
printf("Computer count:");
if ((s + 1) % 3 == 0)
printf(" %d\n", ++s);
else
if ((s + 2) % 3 == 0)
{
s += 2;
printf(" %d\n", s);
}
else
{
c = rand() % 2 + 1;
s += c;
printf(" %d\n", s);
}
return s;
}
简单代码谁数到50谁就赢的代码,可以任意改 展开
1个回答
展开全部
import random
def player(tol):
inp = 100
while inp > 2 or inp < 1 or inp + tol > 50:
inp = int(raw_input("Please count (1 or 2): "))
return inp + tol
def computer(tol):
if tol + 1 == 50 or (tol + 1) % 3 == 0:
tol += 1
elif tol + 2 == 50 or (tol + 2) % 3 == 0:
tol += 2
else:
tol += int(random.random() * 2) + 1
print("Computer count: {}".format(tol))
return tol
def main():
tol = 0
print("* * * * * * * * Grab Fifty * * * * * * * *")
print("Game Begin")
whose_turn = player
if random.random > .5:
whose_turn = computer
while tol != 50:
tol = whose_turn(tol)
if tol == 50:
if whose_turn == player:
print("You Win!")
else:
print("You Lose!")
break
whose_turn = player if whose_turn == computer else computer
print("* * * * * * * * Game Over * * * * * * * *")
if __name__ == "__main__":
main()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询