fork(5) download
  1. import sys;
  2.  
  3. def drawCuboid(w, h, d):
  4. mat=[];
  5. #Initialize character matrix
  6. totalH=d+1+h;
  7. totalW=d+w*5+1;
  8. for i in range(0,totalH+1):
  9. mat.append([]);
  10. sys.stdout.write('\n');
  11. #Fill top side
  12. for i in range(0,d+1):
  13. for j in range(0,d-i):
  14. mat[i].append(' ');
  15. for j in range(0,(w*5 +1)):
  16. gapChar='/';
  17. if (i==0):
  18. gapChar=' ';
  19. if j%5==0:
  20. mat[i].append(gapChar);
  21. else:
  22. mat[i].append('_');
  23. #Fill front side
  24. for i in range(0,h):
  25. for j in range(0,w*5 +1):
  26. if j%5==0:
  27. mat[i+d+1].append('|');
  28. else:
  29. mat[i+d+1].append('_');
  30. #Fill right side
  31. for i in range(1,d+h+1):
  32. while (len(mat[i])<=(w*5+(totalH-i)))and(len(mat[i])<totalW):
  33. if (len(mat[i])<=totalW and len(mat[i])==(w*5+(totalH-i))):
  34. mat[i].append('/');
  35. else:
  36. mat[i].append('|');
  37. printMatrix(mat);
  38.  
  39. def printMatrix(mat):
  40. for i in range(0,len(mat)):
  41. for j in range(0, len(mat[i])):
  42. sys.stdout.write(mat[i][j]);
  43. sys.stdout.write('\n');
  44. w=int(input('Enter width '));
  45.  
  46. h=int(input('Enter height '));
  47.  
  48. d=int(input('Enter depth '));
  49.  
  50. drawCuboid(w,h,d);
Success #stdin #stdout 0.15s 10256KB
stdin
3
5
3
stdout
Enter width Enter height Enter depth 
    ____ ____ ____ 
  /____/____/____/|
 /____/____/____/||
/____/____/____/|||
|____|____|____||||
|____|____|____||||
|____|____|____|||/
|____|____|____||/
|____|____|____|/