0

I'm making a small program that pick random people in a list (a proget for school). The code works fine:

import numpy as np

people = ["0 = Baiesi", "1 = Balducci", "2 = Bulgarelli", "3 = Caffaggi", "4 = Caprara", "5 = Dodi", "6 = Fattore", "7 = Felici", '8 = Marcolin', '9 = Mascagni', '10 = Moretti', '11 = Moschini','12 = Patelli','13 = Sandu','14 = Spinelli','15 = Stevens','16 = Zani']

print(*people, sep = "\n")

n = int(input('Number of people to pick: '))

numbers = [i for i in list(range(len(people)))]
extracted = np.random.choice(numbers, size=n, replace=False)
 
print(extracted)

However I want it to have a specific layout, but I have no idea how to do it. I have done some research online but I didn't find anything that was suited for this case.

This is the current output:

my output

This is the output I am looking for:

output i want

Basically I want to create two "colums", the left one is where the list of people is, the right one is where there is the "user guided" part. I hope I explained myself well.

Has someone any idea on how it could be done?

Edoardo Balducci
  • 332
  • 1
  • 10
  • Alright thanks, I'm gonna do it :) – Edoardo Balducci Apr 13 '22 at 15:40
  • 1
    Since you're on Linux, you should probably look into the [curses](https://docs.python.org/3/library/curses.html) library. – RoadieRich Apr 13 '22 at 15:56
  • thanks for the suggestion, but I was searching a more multi-platform solution since I'm using windows on my laptop – Edoardo Balducci Apr 13 '22 at 16:55
  • I don't think you can do that. There's the possibility to overwrite the current line on `stdout` (see [here](https://stackoverflow.com/questions/5419389/how-to-overwrite-the-previous-print-to-stdout-in-python)), but I don't think you can back further. (But maybe I misunderstood your intension.) – Timus Apr 14 '22 at 08:42
  • I was thinking about using `rich` module's tables (see [here](https://rich.readthedocs.io/en/stable/tables.html)), which have a similar approach to what u are suggesting. The problem is that the table is printed "row by row" and not "colums by colums" (if this make sense) that is what I want. Basically I want to: 1) firstly print the full list of the name 2) secondly print the "user guided" part ("Number of people to pick: ...") – Edoardo Balducci Apr 14 '22 at 11:32
  • But the problem is that you're asking for `input` in-between: I think there's no way back after that? – Timus Apr 15 '22 at 12:54

0 Answers0