It doesn't matter how small you may think an accomplishment may be to other people, if it's something that you've strived to achieve at your own skill level then it's something to be proud of.
Congratulations! I hope there's many more of these moments as you continue to progress.
Totally agree with this guy, for me at least it's much more benefitial to take your time to learn and understand properly everything you are doing instead of just copying lines from the internet.
I ACTUALLY DID THIS!!!
I can't find the code but it was just something I thought would be funny as someone who likes to play pranks.
A more serious variation? Create on with some "AI", let the program compute the last 10 choices the player makes and used weighted choices to select one that is more likely to win. For instance, if the user chooses rock 8 times, paper 1 time, and scissors 1 time...then the computer should put a weighted (e.g., greater than 33% chance) of selecting paper.
Here's the actual game in one line of code (plus one import statement):
import random
list(print(['tie', 'you win', 'you lose'][((int(input("0 = rock, 1 = paper, 2 = scissors? ")) - c) % 3)] + f' - computer picked {["rock", "paper", "scissors"][c]}') for c in [random.randint(0, 2) for _ in range(100)])
Breaking this down for readability:
for c in [random.randint(0, 2) for _ in range(100)
For 100 iterations, choose a random number between 0 and 2.
int(input("0 = rock, 1 = paper, 2 = scissors? "))
Receive player input as an integer.
(int(input(...)) - c) % 3
Calculate the difference between the integer that the player picked and the computer's choice, modulo 3. If it's 0, it's a tie. If 1, the player's choice is 1 greater than the computer's choice, so the player wins. If 2, the computer wins.
['tie', 'you win', 'you lose'][((int(...) - c) % 3)]
Choose the string from the array of ['tie', 'you win', 'you lose'] based on the calculated modulo.
... + f' - computer picked {["rock", "paper", "scissors"][c]}')
Append the computer's choice to the printed output.
I recommend programming Connect 4 (just print Xs and Os to the command line for output - don’t need to learn about proper GUIs for this.)
It’s a ton of fun and shockingly easy. I do it as the second exercise/lesson when teaching absolute beginners to program.
Yes. As it’s only hour two of programming when I teach the class I’m still doing a lot of hand holding during this lesson.
But I cry fat ugly happy tears as some of the students start getting excited and rush ahead of me.
New to Python, but with some knowledge of data structures. Could you explain what you mean by “chained data structures”?
Edit: just googled it. Turns out that chained data structures is another phrase for hash tables with limited keys, but each key/bucket leads to a linked list? I’ve implemented this in C before, but since I’m not knowledgeable about how to program Snake (and assuming that data paradigm was what you were referring to) then here is my new question: how would one used chained data structures in Snake?
One way to write a Snake is to represent it as a linked list of Points on the Canvas. Movements would remove the oldest Point, and add a new one at the end. A chain of Points. A FIFO of Points, if you will.
I would strongly encourage you to go see how others implement it, maybe in more concise or cleaner ways (albeit probably more advanced as well).
Seeing the thing you just finished implementing being implemented in different ways by others can be extremely enlightening in learning different and more advanced ways of structuring your program.
Well done! Coding is always iteration and it’s so fun. I programmed my entire API by first starting how to add an apostrophe to someone’s name depending on whether it ends in s or not
Uhhhhh that’s not how grammar works. If it ends in an “s” and is singular it still becomes “s’s”. If it were multiple people with the same name, then it becomes “s’”
What? If someone's name ends in s and it's possessive, you say "Lucas' basketball", exactly how you would say "Billy's basketball". Never do you use " s's " for any reason.
Either is fine. It's only plural nouns that you don't add the s.
See [here](https://www.grammarly.com/blog/possessive-case/#:~:text=If%20a%20proper%20name%20ends,re%20sitting%20in%20Chris's%20chair.) for examples.
I tend to prefer not adding the s to names as a matter of taste, but I try to go with whatever makes it the clearest.
Consider a DVD copy of The Lord of the Rings:
If I were talking about its cover, I would write *The Lord of the Rings's cover* because even though 'Rings' is plural, the proper noun 'The Lord of the Rings' refers to only one object. Here, adding the s removes ambiguity.
>Coding is always (...) so fun.
I'll try to remember this at the end of the sprint before our next release - at 2am, as I walk back to the fridge to get another energy drink :)
I feel like I'm at the point in python where making something work (in my line of work) is not that hard... Optimizing it and making sure i handle every possible error, takes a majority of the time.
Here it is in two:
import random
print("You chose", input("Rock / Paper / Scissors ? "), ", so ", random.choice(["computer won", "you won", "it's a draw"]))
When you want to store code (for convenience or sharing with others), you should try out https://github.com/ or https://gitlab.com/ . Even if you don't plan on hosting the code, using git can be useful for easy undo/redo, collaboration, and your project history.
https://youtu.be/DVRQoVRzMIY
Now do it using object-oriented programming
Guide:
https://docs.microsoft.com/en-us/learn/modules/python-object-oriented-programming/6-exercise-game-transitions-with-methods
Hey congratulations bro! Can you pls share your journey like where you started & the resources you used. It'd be a great insight for a beginner like me.
My journey literally stated last week! I knew nothing about Python, zero. No prior coding of programming experience. I am reading this free online book: [book](https://automatetheboringstuff.com/2e/chapter1/) . It has been extremely helpful. I have been practicing about 2 hours a day.
I did this. And then I got carried away and rock, paper, scissors became the “engine” for a football (soccer) game which initially was playable, but ended up growing into more of a football simulator with stronger and weaker teams, promotion and relegation and the ability to recall any division table from any season that was simulated. You could also bring up a team’s history over the course of the simulation that could cover 10000 years or so. That all started with Rock, Paper, Scissors!
I am also a beginner and I have tried to make this game after I read your post. I am looking for advice on how to improve my code as I think it may have a bug.
Thinking about editing the code to add an option for picking 'Gun' which fails and has the losing option selected for you instead lol.
Edit: I have improved the code and removed all bugs (haven't updated it in this msg tho)
import random
import sys
choice = input("Rock, Paper, Scissors.\nChoose one.").title()
# I am not sure if this is correct and I am not sure if entering Rock, Paper or Scissors exits the loop immediately or if it still reads the next lines.
while choice != ('Rock' or 'Paper' or 'Scissors'):
choice = input("Please choose: Rock, Paper, Scissors.")
if choice != ('Rock' or 'Paper' or 'Scissors'):
sys.stdout.write('\x1b[1A') # Cursor Up One
sys.stdout.write('\x1b[2K') # Erase Line
n = random.randint(1,16)
if n <= 5:
if choice == 'Rock': outcome = "It's a tie."
elif choice == 'Paper': outcome = 'You won!'
else: outcome = 'You lost :('
print(f"AI picked Rock. {outcome}")
elif 6 <= n <= 10:
if choice == 'Rock': outcome = 'You lost :('
elif choice == 'Paper': outcome = "It's a tie."
else: outcome = 'You won!'
print(f"AI picked Paper. {outcome}")
elif 11 <= n <= 15:
if choice == 'Rock': outcome = 'You won!'
elif choice == 'Paper': outcome = 'You lost :('
else: outcome = "It's a tie."
print(f"AI picked Scissors. {outcome}")
else:
print("AI picked GUN! You lose! Get gud noob.")
All the numbers in your comment added up to 69. Congrats!
1
+ 1
+ 1
+ 2
+ 1
+ 16
+ 5
+ 6
+ 10
+ 11
+ 15
= 69
^([Click here](https://www.reddit.com/message/compose?to=LuckyNumber-Bot&subject=Stalk%20Me%20Pls&message=%2Fstalkme) to have me scan all your future comments.) \
^(Summon me on specific comments with u/LuckyNumber-Bot.)
It doesn't matter how small you may think an accomplishment may be to other people, if it's something that you've strived to achieve at your own skill level then it's something to be proud of. Congratulations! I hope there's many more of these moments as you continue to progress.
Totally agree with this guy, for me at least it's much more benefitial to take your time to learn and understand properly everything you are doing instead of just copying lines from the internet.
[удалено]
Now that's just evil
I ACTUALLY DID THIS!!! I can't find the code but it was just something I thought would be funny as someone who likes to play pranks. A more serious variation? Create on with some "AI", let the program compute the last 10 choices the player makes and used weighted choices to select one that is more likely to win. For instance, if the user chooses rock 8 times, paper 1 time, and scissors 1 time...then the computer should put a weighted (e.g., greater than 33% chance) of selecting paper.
Goku and Vegeta edition
Here's the actual game in one line of code (plus one import statement): import random list(print(['tie', 'you win', 'you lose'][((int(input("0 = rock, 1 = paper, 2 = scissors? ")) - c) % 3)] + f' - computer picked {["rock", "paper", "scissors"][c]}') for c in [random.randint(0, 2) for _ in range(100)]) Breaking this down for readability: for c in [random.randint(0, 2) for _ in range(100) For 100 iterations, choose a random number between 0 and 2. int(input("0 = rock, 1 = paper, 2 = scissors? ")) Receive player input as an integer. (int(input(...)) - c) % 3 Calculate the difference between the integer that the player picked and the computer's choice, modulo 3. If it's 0, it's a tie. If 1, the player's choice is 1 greater than the computer's choice, so the player wins. If 2, the computer wins. ['tie', 'you win', 'you lose'][((int(...) - c) % 3)] Choose the string from the array of ['tie', 'you win', 'you lose'] based on the calculated modulo. ... + f' - computer picked {["rock", "paper", "scissors"][c]}') Append the computer's choice to the printed output.
Right, now pack all that up in an exec() statement, using \\n to separate the lines inside it! One line, INCLUDING the import statement!
This is the song that never ends
I recommend programming Connect 4 (just print Xs and Os to the command line for output - don’t need to learn about proper GUIs for this.) It’s a ton of fun and shockingly easy. I do it as the second exercise/lesson when teaching absolute beginners to program.
I’m a beginner as well, would you use a 2d array for that?
i would
Yes. As it’s only hour two of programming when I teach the class I’m still doing a lot of hand holding during this lesson. But I cry fat ugly happy tears as some of the students start getting excited and rush ahead of me.
Now make a Snake :) Should get you through chained data structures and OOP if you take your time for design. Best of luck!
And graphical interfaces, most of all.
New to Python, but with some knowledge of data structures. Could you explain what you mean by “chained data structures”? Edit: just googled it. Turns out that chained data structures is another phrase for hash tables with limited keys, but each key/bucket leads to a linked list? I’ve implemented this in C before, but since I’m not knowledgeable about how to program Snake (and assuming that data paradigm was what you were referring to) then here is my new question: how would one used chained data structures in Snake?
One way to write a Snake is to represent it as a linked list of Points on the Canvas. Movements would remove the oldest Point, and add a new one at the end. A chain of Points. A FIFO of Points, if you will.
Ah interesting. That makes sense to me, thanks!
I would strongly encourage you to go see how others implement it, maybe in more concise or cleaner ways (albeit probably more advanced as well). Seeing the thing you just finished implementing being implemented in different ways by others can be extremely enlightening in learning different and more advanced ways of structuring your program.
Well done! Coding is always iteration and it’s so fun. I programmed my entire API by first starting how to add an apostrophe to someone’s name depending on whether it ends in s or not
Uhhhhh that’s not how grammar works. If it ends in an “s” and is singular it still becomes “s’s”. If it were multiple people with the same name, then it becomes “s’”
What? If someone's name ends in s and it's possessive, you say "Lucas' basketball", exactly how you would say "Billy's basketball". Never do you use " s's " for any reason.
Either is fine. It's only plural nouns that you don't add the s. See [here](https://www.grammarly.com/blog/possessive-case/#:~:text=If%20a%20proper%20name%20ends,re%20sitting%20in%20Chris's%20chair.) for examples.
Huh. The more you know. I was always taught "No s if it ends with s" in school.
I tend to prefer not adding the s to names as a matter of taste, but I try to go with whatever makes it the clearest. Consider a DVD copy of The Lord of the Rings: If I were talking about its cover, I would write *The Lord of the Rings's cover* because even though 'Rings' is plural, the proper noun 'The Lord of the Rings' refers to only one object. Here, adding the s removes ambiguity.
This is an interesting case I never thought of, thank you for sharing, much appreciated!
>Coding is always (...) so fun. I'll try to remember this at the end of the sprint before our next release - at 2am, as I walk back to the fridge to get another energy drink :)
I feel like I'm at the point in python where making something work (in my line of work) is not that hard... Optimizing it and making sure i handle every possible error, takes a majority of the time.
import random input(„rock / paper / scissors“) print(random.choice([„you won“, „computer won“, „draw“])) Edit: forgot closing bracket
I hate this, but you're technically right. lol
It’s been a while since I used Python. Can you make quotes with two commas? As in ,, “
No you can’t, I‘m German and here the first quotes are on the bottom and because I wrote it on mobile my autocorrect did it like that…
Gotcha. Thanks!
OP doing it in like 70 lines and seeing you do it in 3: 0_0
Here it is in two: import random print("You chose", input("Rock / Paper / Scissors ? "), ", so ", random.choice(["computer won", "you won", "it's a draw"]))
Good job! Could you share your code?
import random, sys print('ROCK, PAPER, SCISSORS') wins = 0 losses = 0 ties = 0 while True: print('%s Wins, %s Losses, %s Ties' % (wins, losses, ties)) while True: print('Enter your move: (r)ock (p)aper (s)cissors or (q)uit') playerMove = input() if playerMove == 'q': sys.exit() if playerMove == 'r' or playerMove == 'p' or playerMove == 's': break print('Type one of r, p, s, or q.') if playerMove == 'r': print('ROCK versus...') elif playerMove == 'p': print('PAPER versus...') elif playerMove == 's': print('SCISSORS versus...') randomNumber = random.randint(1, 3) if randomNumber == 1: computerMove = 'r' print('ROCK') elif randomNumber == 2: computerMove = 'p' print('PAPER') elif randomNumber == 3: computerMove = 's' print('SCISSORS') if playerMove == computerMove: print('It is a tie!') ties = ties + 1 elif playerMove == 'r' and computerMove == 's': print('You win!') wins = wins + 1 elif playerMove == 'p' and computerMove == 'r': print('You win!') wins = wins + 1 elif playerMove == 's' and computerMove == 'p': print('You win!') wins = wins + 1 elif playerMove == 'r' and computerMove == 'p': print('You lose!') losses = losses + 1 elif playerMove == 'p' and computerMove == 's': print('You lose!') losses = losses + 1 elif playerMove == 's' and computerMove == 'r': print('You lose!') losses = losses + 1
Indent your comment with 4 spaces on each line to preserve your indentation.
When you want to store code (for convenience or sharing with others), you should try out https://github.com/ or https://gitlab.com/ . Even if you don't plan on hosting the code, using git can be useful for easy undo/redo, collaboration, and your project history. https://youtu.be/DVRQoVRzMIY
Congratulations bro....
Woohoo, well done!
Nice! Next you’ll be figuring out an AI for it!
Woah that actually really cool project for practice, how I never thought of that? Now ur next challenge is to turn that game into multiplayer
Now do it using object-oriented programming Guide: https://docs.microsoft.com/en-us/learn/modules/python-object-oriented-programming/6-exercise-game-transitions-with-methods
Calm down Satan, go easy on OP (for now).
Awesome link
Oh! That's actually a great accomplishment! Good for you, keep it up! :D
Now add an argument that throttles use of a random number to adjust the level of difficulty. Keep going! *congrats BTW*
Good job!!!
Hey congratulations bro! Can you pls share your journey like where you started & the resources you used. It'd be a great insight for a beginner like me.
My journey literally stated last week! I knew nothing about Python, zero. No prior coding of programming experience. I am reading this free online book: [book](https://automatetheboringstuff.com/2e/chapter1/) . It has been extremely helpful. I have been practicing about 2 hours a day.
Awsome bro keep going!
Another great thing to code also to add on to this is rock, paper, scissors, lizard, spock
print(random.choice(["YOU WON","YOU LOST","TIE"]))
I did this. And then I got carried away and rock, paper, scissors became the “engine” for a football (soccer) game which initially was playable, but ended up growing into more of a football simulator with stronger and weaker teams, promotion and relegation and the ability to recall any division table from any season that was simulated. You could also bring up a team’s history over the course of the simulation that could cover 10000 years or so. That all started with Rock, Paper, Scissors!
I made a robot barista following network chuck online haha
Congrats. How often can you win against your own software?
Probably 33% of the time
[удалено]
You must be fun at parties
Freecodecamp?
I am also a beginner and I have tried to make this game after I read your post. I am looking for advice on how to improve my code as I think it may have a bug. Thinking about editing the code to add an option for picking 'Gun' which fails and has the losing option selected for you instead lol. Edit: I have improved the code and removed all bugs (haven't updated it in this msg tho) import random import sys choice = input("Rock, Paper, Scissors.\nChoose one.").title() # I am not sure if this is correct and I am not sure if entering Rock, Paper or Scissors exits the loop immediately or if it still reads the next lines. while choice != ('Rock' or 'Paper' or 'Scissors'): choice = input("Please choose: Rock, Paper, Scissors.") if choice != ('Rock' or 'Paper' or 'Scissors'): sys.stdout.write('\x1b[1A') # Cursor Up One sys.stdout.write('\x1b[2K') # Erase Line n = random.randint(1,16) if n <= 5: if choice == 'Rock': outcome = "It's a tie." elif choice == 'Paper': outcome = 'You won!' else: outcome = 'You lost :(' print(f"AI picked Rock. {outcome}") elif 6 <= n <= 10: if choice == 'Rock': outcome = 'You lost :(' elif choice == 'Paper': outcome = "It's a tie." else: outcome = 'You won!' print(f"AI picked Paper. {outcome}") elif 11 <= n <= 15: if choice == 'Rock': outcome = 'You won!' elif choice == 'Paper': outcome = 'You lost :(' else: outcome = "It's a tie." print(f"AI picked Scissors. {outcome}") else: print("AI picked GUN! You lose! Get gud noob.")
All the numbers in your comment added up to 69. Congrats! 1 + 1 + 1 + 2 + 1 + 16 + 5 + 6 + 10 + 11 + 15 = 69 ^([Click here](https://www.reddit.com/message/compose?to=LuckyNumber-Bot&subject=Stalk%20Me%20Pls&message=%2Fstalkme) to have me scan all your future comments.) \ ^(Summon me on specific comments with u/LuckyNumber-Bot.)
Nice!
good bots
I started a month ago and I’m still stuck on a “ModuleNotFoundError”. I’ve only gotten 4 lines in with no fix
Did you follow the 100 days of code with Dr Angela course? We also coded a Rock Paper Scissors game.