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