Can I create this system in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can I create this system in python?

I want to create a small code which will work as follows. There will be an empty list like players=[ ] Then an input will be taken saying the number of players which can be stored in player_num=[ ]. Now what I want to do is, The number of players given will give a promt asking for the names for that many times. And all the names will be saved in players. Like 3 names will be saved if 3 is input as player_num. Then the program will repeat a promt like this, Player 1 Enter your word: ... Player 2 Enter your word: ... Player 3 Enter your word: In between these ... there are a few lines of code. So i think i explained it pretty well. So please help me with this

29th Jan 2020, 3:22 PM
Zodiac ZNaim
Zodiac ZNaim - avatar
7 Answers
+ 4
You have laid this all out pretty well, step by step. Now the coding needs to be done - by you! 😉 Make an honest attempt, and if you have a specific problem with that code you wrote, feel free to ask us!
29th Jan 2020, 3:24 PM
HonFu
HonFu - avatar
+ 3
You take input, turn it into an int, let a for loop run over a range of that int. Then use the loop variable to output the player's number, take the input and append it to a player list which you have created before. It is actually all so basic that my description sounds as if I had just rewritten the task. You'll definitely need nothing which you haven't encountered yet in your half-finished tutorial - but now you need to think and actually *use* what you've learned. It's the only way to improve. Good luck, keep us posted!
29th Jan 2020, 4:34 PM
HonFu
HonFu - avatar
+ 2
Hon Fu Yeah bro. I didn't think it was going to be this easy to code. I alreafy created the core game that I mentioned before. Now Im just working on this player settings and funally sorting all the words that the players typed. But now i have no idea how to write this code where the program asks each user for an input in a loop. Give me some kind of hint please
29th Jan 2020, 3:27 PM
Zodiac ZNaim
Zodiac ZNaim - avatar
+ 2
HonFu I came up with this and I think I did it pretty well. players_num = int(input("Enter the number of players: ")) for i in range(players_num): players.append(input("Enter name of the player: ")) print() print("People that are currently playing the game are: ") print() for player in players: print(player) Now how do I make that thing ask each user individual inputs in game. Thats where I have no clue how to do it.
30th Jan 2020, 2:05 PM
Zodiac ZNaim
Zodiac ZNaim - avatar
+ 2
Hi, Zodiac ZNaim, thanks for sharing! One thing: If you show code, it's best if you upload it just as it runs correctly on Playground and link it here. The way you did it, I first had to manually correct the indentations to see how or if it works. This is the cleaned up version with the missing list players added: players_num = int(input("Enter the number of players: ")) players = [] for i in range(players_num): players.append(input("Enter name of the player: ")) print() print("People that are currently playing the game are: ") print() for player in players: print(player) But you have already demonstrated how you take inputs! What's different in the game than before it? Loop over players and perform the operation you want for each one! Maybe you can explain more clearly what your problem is?
30th Jan 2020, 2:18 PM
HonFu
HonFu - avatar
+ 2
HonFu Im extremely sorry for your inconvinience. I didn't know I needed to do that with the code as Im new here. Ill take care of it next time. And In sorry for not being able to explain my problem. Now heres the thing. I created the list ok no prob. Ut how do i loop the thing with the players name up front as the input gets added to another list and goest through several possible input possibilities and for them there are several lones of codes. So far the single player stuff is working just fine. But I cant figure out how to make this thing multiplayer by looping through the players. Maybe it will make more sence if i upload my code. But I dont want to do that yet. So yeah, thats what I have to say.
30th Jan 2020, 2:35 PM
Zodiac ZNaim
Zodiac ZNaim - avatar
+ 2
No, no, don't be sorry. :) It's just that if you give us only half information, we might have to shoot blindly, and might not be able to figure out if or how exactly it works. Especially indentation is crucial in Python, so if you change that for optical reasons, the copy may not represent anymore what the code really was.
30th Jan 2020, 3:35 PM
HonFu
HonFu - avatar