Can Sup Forums do this?

Write a function that takes a list of strings an prints them, one per line, in a rectangular frame. For example the list ["Hello", "World", "in", "a", "frame"] gets printed as:

*********
* Hello *
* World *
* in *
* a *
* frame *
*********

Other urls found in this thread:

hastebin.com/qagicuguda.c
twitter.com/NSFWRedditGif

*********
* Hello *
* World *
* in *
* a *
* frame *
*********

Asterisks need to be inline

You can't be serious this is shit easy goy

Iterate over all elements to find the max length. Then pad all the shorter strings with the required number of spaces to match that length. Pretty simple

>Find the widest string.
>Format the rest of the prints to be the same width as widest string

Wow that was hard

Ask /sci/, they are the homework board.

max_len = len(max(mah_list, key=len)) + 2
for i in mah_list:
if i == mah_list[0]:
print(max_len * '*')
print('*' + i + (' ' * (max_len - (len(i) - 1))) + '*')


Not sure if it works.
t.retard on the phone

I have already done it guys. I just want to see what it would look like in other languages.

use code tags retard

this

print("Dont be so angry user")

Kek
Remove that print '*' from loop and add one before and after.

t.same phone retard

He doesn't write code on his phone. Ahaha oh wow.

I might be stupid, but not that stupid...

Or better yet, I don't hate myself that much.

#!/bin/bash
frame_start() {
declare -i i
for (( i=0; i max_len )); then
max_len=${#word}
fi
done

frame_start "$(( max_len + 4 ))"
printf '* %'"$max_len"'s *\n' "$@"
frame_start "$(( max_len + 4 ))"


it's not left justified but whatever, sue me. it would just mean another for loop and some printf indecipherable formatting cancer like %s%-*i "string" some_num.

That is really poorly programmed.

count=0
for str in ["Hello", "World", "in", "a", "frame"]:
if len(str)>0 :
count=count+1
k=9-len(str)
# print(k)
if count==1:
print("***********")
print("*"+str+(" "*k)+"*" )
print("***********")


It just werks :^)

public class StringRectangle {
public static void main(String[] args) {
int max = 0;
for(int i = 0;i max ? args[i].length():max;
for(int i = 0;i

Yeah i know, its it's pretty fucking bad. It works though, and that counts for something. I guess.

import java.util.Scanner;

public class Bin2Dec {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a binary number for it's decimal equivalent: ");
String number = input.nextLine();
System.out.println(bin2Dec(number));
}

public static int bin2Dec(String number) {
int result = 0;
for(int i = 0;i

#!/usr/bin/env ruby

def encase(words)
max_length = words.max_by {|w| w.length }.length
puts '*'*(max_length + 4)
words.each {|w| puts "* #{w.ljust(max_length)} *" }
puts '*'*(max_length + 4)
end

encase(ARGV)
$ ./encase.rb hello world in a frame
*********
* hello *
* world *
* in *
* a *
* frame *
*********

Bumping for other languages

printf "* %-${max_len}s *\n" "$@"

for

#!/usr/bin/python3
import sys
s=sys.argv[1:]
ml=max([len(x) for x in s])
f="*"*(ml+2)
print(f+"\n"+"\n".join(["*"+x+" "*(ml-len(x))+"*" for x in s])+"\n"+f)


Not sure if it can be even more shortened.

KISAMAAA

C
for some reason my code is blocked.
hastebin.com/qagicuguda.c