Hello to all brilliant peoples of the community. I recently started studying python programming language and tried creating a simple game of Stone paper Scissors. We all have played the game of Stone Paper Scissors in our childhood. Stone paper scissors is a hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand. These shapes are "Stone" (a closed fist), "paper" (a flat hand), and "scissors" (a fist with the index finger and middle finger extended,).
Image Source
I tried to implement the logic of the game programmatically. In this simple python program one can play the game with computer. It's simple yet enjoyable.
The number 1 is for stone, 2 is for Paper and 3 is for Scissors.
The Computer chose it's move randomly. Its a tie if both the player and computer have the same choice and gains the value of 1 if anyone wins.
The game goes on till anyone of the player or computer have 5 points. Whoever scores 5 points earlier will win. Then one can chose to play again or exit.
It's not a complex game but really interesting to build it. The snapshot of the source code of the program are as follows.
The program contains 100 lines of code and was created on IDLE. I know it can be optimized but I am just beginning to learn python so it's a start🙂🙂🙂🙂🙂. If you guys have any suggestions to improve the code feel free to comment. Thank you all, have a great life. This is @biggestloser signing off....
This is definitively a nice start for a beginner but as a Python developer with some experience, I would like to give you some quick suggestions to make your code better:
<ul> <li><p dir="auto">You should never declare functions inside loops. This is very inefficient as the program is declaring the same code over and over, which slows the code and may waste additional memory space. <li><p dir="auto">You should not access the global variables in the body of the function. This is considered a bad design as modifying their values inside the function may break the program. Instead, you should declare the needed variables as function parameters then call the functions with values of those global variables. <li><p dir="auto"><code>if c=='y' or c=='Y': can be simplified to <code>if c.lower() == 'y':. <p dir="auto">That's what I have noticed until now, I hope that will help you in the future.Great suggestion 👍 , experience does matter.
I guess you are new to hive so WELCOME....
Yes, I am very new to HIVE, thank you.
I am more interested in developing a Dapp on HIVE than spending my time posting here. Haha! I am a strange person.
This is so awesome, I can only envy a skilled programmer like you. I cannot understand even 0.0001% of this process hahaha. Anyway, this is so unique and very rare to see on this platform. So I should congrats you for this awesome post. I saw this rock-paper-scissors game while playing Dice Dreams. Call me to your post, next time if you ever write a new program, cheers, ainie
Come on mam, your praise is making me blush🤗🤗🤗. I am not a skilled programmer just a beginner and while learning python I thought of developing this program which people can relate to.
Most of the successful posts have beautiful pictures and a good story. My posts lack audience and I still have to learn a lot..
If I had 0.0001% talent as yours I can become a better blogger. Thanks for always encouraging and motivating me.😊😊😊
Your response motivated me and in future from time to time I will create some technical posts also along with my other posts.
Thanks again, have a great life................Thanks @tobetada, @smartvote, @gloriaolar, @fatman, @tipy and @optimusre for upvoting this post. I am truly overwhelmed by your support, never thought that a progamming post can also get upvotes, it is not usual.
I'd love to see more programming posts :)
Will try to create more of them, Thanks for commenting