1MD3 - Winter 2006 - Assignment #1
Generated for Student ID: 0547334
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);
int main() {
int w, m, q;
char n[] =
"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";
q = strlen(n);
w = 1;
m = q - 9;
while (++w <= m) {
f(n, q);
g(n, q);
}
return 0;
}
void f(char c[], int y) {
int a, x;
a = 5;
x = y - 3;
do {
printf("%c", c[x - a]);
} while (x >= a++);
printf("\n\n");
}
void g(char v[], int p) {
char b;
int z, r, u;
for (r = 9, u = p - 2; ++r < u; ) {
z = u - r;
if (4*(z/4) == z) {
b = v[r];
v[r] = v[u];
v[u] = b;
}
}
}