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