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