TUTORIAL: CREATING A SIMPLE GUESSING GAME

in #utopian-io6 years ago (edited)

image
Image source
Repository: Python, Open Source Repository
What you will learn?

  • Coding a guessing game (no graphics)
    REQUIREMENTS:
  • SMARTPHONE
  • QPYTHON 3
    DIFFICULTY: BASIC
    TUTORIAL CONTENTS

This code was written when I started coding, then I didn't know about class so that's why I didn't add one and besides this code doesn't need a class cause it's a simple one.

import sys
import os
import subprocess as sp
from getpass import getpass
from time import sleep
entered = []
clap = []
realword = getpass("Enter a word you would like someone to guess from")

hint = input("Write a hint.\nNote: This is not the word and can be seen by the people guessing the word. >>>")
print("Please wait while we load the game...")

fling = realword.upper()
realword = realword.upper()
sleep(5)
sp.call('cls' ,shell = True)
b = len(realword)
l = len(clap)
l = l + 1
y = len(realword)
y = y + 3
t = 1
while t <= y:

print(str(t) + " of " + str(y) + " tries.")
print("Hint: " + hint + "...")
enter = input("Can you guess a letter in the word >>>")
enter = enter.upper()
if enter in realword:
    entered.append(enter)
    
else:
    print("Wrong answer!")
for g in realword:
    if g in entered:
        print(g + "\t")
        clap.append(g)
       
    else:
        print("------")
l = len(clap)
while b == l:
    print("Congratulations!!!\nYou have figured it all out!!!")
    sleep(10)
    sys.exit()
del clap [:]   

t += 1

sp.call('cls' ,shell = True)
print("Sorry you could not figure it out within the number of tries...\nThe word was " + fling)
print(" ")
print(" o o o o o ")
print(" o o ")
print(" o o")
print(" o o o o")
print(" o o")
print(" o o")
print(" o v o")
print(" o o")
print(" o o")
print(" o ______ o")
print(" o ( ) o")
print(" o o")
print(" o o o o o ")
sleep(10)

It's a simple code and no graphics so I added the dots to give it little graphics. This game consists of two players where one inputs the word that he wants the other to guess, I coded the actual word to disappear immediately it's inputted. The clues are given based one how many letters the word to be guessed is. The output should look like this
image
image
image

When you win there's a kind of smiley face that congratulates you.

Proof of work
GITHUB REPOSITORY

Sort:  

Thank you for your contribution.
This moderation might not be considered due to the below:

  • The tutorial is poorly structured.
  • Doesn´t follow the template for tutorials. See the template here.

Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Please can I edit it and try again

You have collected your daily Power Up! This post received an upvote worth of 0.29$.
Learn how to Power Up Smart here!

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.029
BTC 61039.43
ETH 2460.28
USDT 1.00
SBD 2.66