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