Ask coding questions

← Back to all posts
Center a code.
Elizabeth_Mason

Hello, I am trying to get my code in the center, and I can't figure it out. Can someone send me the code so I can center it?

Answered by Vandesm14 [earned 5 cycles]
View Answer
Voters
Elizabeth_Mason
Comments
hotnewtop
Vandesm14

If you mean CSS:

Elizabeth_Mason

@Vandesm14 Sorry I did specify, I wan to get it centered in python.

Vandesm14

@Elizabeth_Mason Then you need to calculate the length of the string, and the width of the terminal (in characters).
Then just subtract the terminal width by the string length set that to your padding value. Then take your padding value and insert padding/2 spaces before the string. Finally, print to console.

JosiahCerda

!DOCTYPE html>

<html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>repl.it</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body style="background-color:BlueViolet;"> <h1 style="color:Fuchsia;">JOSIAH CERDA</h1> <table border='30'style="border:2px solid rgb(181, 3, 235);"><h1 style="color:Aqua;">DAILY SCHEDULE</h1></td> <tr> <th><h1></h1></th> <th><h1 style="color:GhostWhite;">ODD</h1></th> <th><h1 style="color:GhostWhite;">EVEN</h1></th> </tr> <tr> <th><h1 style="color:GhostWhite;">Block 1-2</h1></th> <th><h1 style="color:GhostWhite;">English</h1></th> <th><h1 style="color:GhostWhite;">spanish</h1></th> </tr> <tr> <th><h1 style="color:GhostWhite;">Block 3-4</h1></th> <th><h1 style="color:GhostWhite;">bible</h1></th> <th><h1 style="color:GhostWhite;">web dev</h1></th> </tr> <th><h1 style="color:GhostWhite;">Block 5-6</h1></th> <th><h1 style="color:GhostWhite;">physics</h1></th> <th><h1 style="color:GhostWhite;">geometry</h1></th> </tr> <tr> <th><h1 style="color:GhostWhite;">Block 7-8</h1></th> <th><h1 style="color:GhostWhite;">SS</h1></th> <th><h1 style="color:GhostWhite;">Draw 1</h1></th> </tr></table> <h1 style="color:Fuchsia;">My Aug Prep Activities</h1> <h1 style="color:Aqua;">basketball</h1> <img src='basketball.jpg'alt='basketball' width='400'> <h1><li style=color:Aqua;">Basketball Practice</li></h1> <h1><li style=color:Fuchsia;">streangth and conditioning</li></h1> <h1><li style=color:Aqua;">going to classes</li></h1> <h1 style="color:Fuchsia;">College Program/internships</h1> <h1><li style=color:Aqua;">(UWM College Program)</li></h1> <h1 style="color:Fuchsia;">Faith and Service</h1> <h1><li style=color:Aqua;">I help at my granpas church, and i help others with basketball practice.</li></h1>
</body> </html>