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