-3

I am thinking of games like top eleven, which is an online football management game, and all players have random names, and you can see the opponents players and everything. I was wondering if there was a way of naming an object after a user input or a random.choice for example. Otherwhise, what is the system they would most likely be using? Here is what I tried, which of course returned an error "name Dude is not defined"...

P-S: I don't mean a totally random name of course, just a randomly selected first and last name for example...

whatever ='hello world'
obj = 'Dude'
obj = Objects()
print(Dude.whatever)

   
Jogvi
  • 24
  • 1
  • 6
  • 1
    i didnt got what you men to – Abdul Wahab Rana May 28 '22 at 03:49
  • You don't name the objects that way. How could your future code know what name to use? You create a dictionary, and set `names["Dude"] = Objects()`. – Tim Roberts May 28 '22 at 03:49
  • https://pypi.org/project/names/ Check out this library – HARRIBO May 28 '22 at 03:50
  • 2
    Welcome to Stack Overflow. You seem to have confused names in your program (i.e., variables) for real-world names that are data about some player (i.e., something that you might represent using an *attribute* of the object representing the player). Also, please read [mre] and try to write code that others can actually use to observe the problem, along with a [complete](https://meta.stackoverflow.com/questions/359146) error message that is copied and pasted, rather than described from memory. – Karl Knechtel May 28 '22 at 03:50

2 Answers2

-1

This is usually used in test code, but you can use Faker for generating believable names, company names, etc.

From the documentation:

pip install Faker

(You can use requirements.txt instead if you're trying to build a consistent set of dependencies for a virtual env, but this is a minimalist example).

Python example:

from faker import Faker
fake = Faker()

fake.name()
# 'Lucy Cechtelar'
JasonTrue
  • 18,814
  • 4
  • 35
  • 59
-1

If I'm not wrong, you're asking for a way to generate random valid names for players. So, here is a code

import random

first_names = ['Cristiano', 'Lionel','Robert', 'John', 'Frank']
last_names = ['Martinez','Santos','Bruce','Morgan','James']

select_first_name = first_names[random.randint(0,(len(first_names)-1))]
select_last_name = last_names[random.randint(0,(len(last_names)-1))]

print(f'Name of new player is: {select_first_name +" "+ select_last_name}')

Add first names and last names as much as possible in those respective lists to get more unique valid names every time.

  • Hey!what i meant was rather to create an object with that name, but I've had a satisfactory answer, so thanks anyway! – Jogvi May 28 '22 at 04:17