Jump to content

Estou com dificuladade de passar este codigo em C para phyton


Amanda
 Share

Recommended Posts

Amanda
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct frame {
	char b1,b2;
	int ball1,ball2,score;
};

int ball(int pins)
{
	int jogada; 
	
	printf("Entre com a pontuação da jogada: ");
	scanf("%d", &jogada);
	
	return jogada;
}

void get_frame(struct frame *f)
{
	f->ball1 = ball(10);
	if(f->ball1==10)
	{
		f->ball2 = 0;
		f->b1 = ' ';
		f->b2 = 'X';
		f->score = 10;
		return;
	}

	f->ball2 = ball(10 - f->ball1);
	f->score = f->ball1 + f->ball2;
	f->b1 = f->ball1 ? '0' + f->ball1 : '-';
	f->b2 = f->ball2 ? '0' + f->ball2 : '-';
	if( f->score==10 )
		f->b2 = '/';
}
		
int main()
{
	struct frame game[12];
	int x,score;

	srand((unsigned)time(NULL));
	score = 0;

	/* Simulate 12 potential frames */
	for(x=0;x<12;x++)
		get_frame(&game[x]);
	
	/* properly calculate the scores */
	for(x=0;x<10;x++)
	{
		if( game[x].b2 == 'X' )
		{
			if( game[x+1].b2 == 'X' )
				score += 10 + game[x+1].ball1 + game[x+2].ball1;
			else
				score += 10 + game[x+1].score;
		}
		else if( game[x].b2 == '/' )
			score += 10 + game[x+1].ball1;
		else
			score += game[x].score;
		game[x].score = score;
	}

	/* Display first row, frame numbers */
	for(x=0;x<10;x++)
		printf(" %2d  ",x+1);
	putchar('\n');

	/* Second row, balls rolled */
	for(x=0;x<9;x++)
	{
		if( game[x].b2 == 'X')
			printf("|  |X");
		else
			printf("| %c|%c",game[x].b1,game[x].b2);
	}
	/* Special output for 10th frame */
	if( game[x].b2 == 'X')
	{
		if( game[x+1].b2 == 'X')
		{
			if( game[x+2].b2 == 'X')
				printf("| X|X|X|\n");
			else
				printf("| X|X|%c|\n",game[x+2].b1);
		}
		else
			printf("| X|%c|%c|\n",game[x+1].b1,game[x+1].b2);
	}
	else if( game[x].b2 == '/')
	{
		if( game[x+1].b2 == 'X')
			printf("| %c|/|X|\n",game[x].b1);
		else
			printf("| %c|/|%c|\n",game[x].b1,game[x+1].b1);
	}
	else
		printf("| %c|%c| |\n",game[x].b1,game[x].b2);

	/* Third row, scores */
	for(x=0;x<9;x++)
	{
		printf("| %3d",game[x].score);
	}
	printf("|  %3d |\n",game[x].score);

	return(0);
}

 

Link to comment
Share on other sites

E qual é a tua dificuldade?

Se não colocares as tuas dúvidas de forma clara e concreta ninguém te vai conseguir ajudar.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Amanda

Sou iniciante em phyton, e preciso fazer este código em phyton, mas consegui apenas em C, como não conheço muito bem a estrutura gostaria de saber como deveria faze-lo em phyton

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.