1MD3 - Winter 2006 - Assignment #1

Generated for Student ID: 0474332

Due Date: ???

(You are responsible for verifying that your student number is correct!)

Translate the following C program into Python. Do your best to translate it line by line. In other words, don't write a new Python program from scratch which merely produces the same output; instead try to provide as direct a translation as possible (using the same structure, variable names, and function names.

Useless.c
#include "stdio.h"
#include "string.h"

void f(char[], int);
void g(char[], int);

void f(char b[], int m) {
	int c, v;
	c = 5;
	v = m - 8;

	while (c <= --v) {
		printf("%c", b[v - c]);
	}

	printf("\n\n");
}

void g(char u[], int y) {
	char w;
	int d, q, z;
	q = 2;
	z = y - 4;

	do {
		d = z - q;
		if (2*(d/2) == d) {
			w = u[q];
			u[q] = u[z];
			u[z] = w;
		}
	} while (q < z--);
}

int main() {
	int x, r, a;
	char p[] =
		"Wow, this code is utterly useless!  " \
		"From what kind of deep-seated emotional problems does one have to suffer " \
		"to even conceive of such a ridiculous program?  Meanwhile, the author " \
		"probably labours under the delusion that he's making some clever, " \
		"existentialist comment about the nature of computation.  Sad, really.\n\n";

	a = strlen(p);
	for (x = 0, r = a + 6; r >= x++; ) {
		f(p, a);
		g(p, a);
	}

	return 0;
}