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