`

#Author : Bikash Guragai
#versione : 1.0
#email : bikashguragai@gmail.com or bikashguragai@programmer.net

import random

print ("Hello and welcome")

Name = input("What is your name: ")
print ("Nice to meet you",Name)


ok = input("Click enter to move on")

play = input("Lets play a game")


b = input("Think of any Any number")

c = input("Add that number by it self")
g = random.randint(1,50) 
print ("Now add",g) 
ans = g/2 
h = input("Now divide that number by 2")  
i = input("Now Subtract that number by the number you guessed at first") 
print("your number answer is",ans)

Again = input("Did you like this game yes or no: ")


if Again == "no":
    exit()

else:
    print("Share this to your friends")
    print("Thank you")

`

Dani AI

Generated

Nice, simple arithmetic trick by — it works because the algebra cancels the secret number and leaves half of the random value as the final result. That makes the “guess” deterministic, so the program doesn’t need to know the secret number.

Practical improvements to make the script more robust and less confusing (addresses points from ):

  • Pick an even random value or format the result so the prediction is an integer when you want it to be.
  • Validate and convert input when you actually need numeric values; treat input() results as strings and use int()/float() inside try/except blocks if required.
  • For yes/no questions accept common variants (y, yes, n, no) and compare .strip().lower() so a reply like 1221 is handled as “not yes” rather than causing logic surprises — or re-prompt until a valid answer is given.

A compact, safer Python 3 example (keeps the trick but cleans up prompts, validation, replay and integer output):

import random

def ask(prompt):
    return input(prompt).strip()

def yes(prompt):
    return ask(prompt).lower() in ('y','yes')

def play_once():
    g = random.randrange(2, 50, 2)  # even so half is integral
    ask("Think of a number privately and press Enter when ready...")
    print("Double it, add", g, "then divide by 2 and subtract your original number.")
    ask("Press Enter when done...")
    print("My guess:", g // 2)

if __name__ == "__main__":
    while True:
        play_once()
        if not yes("Play again? (y/N): "):
            print("Thanks for playing.")
            break

Extra ideas: randomize steps, let the program perform the arithmetic if the user is willing to type their number (good for teaching), and follow PEP8 naming/spacing for clearer, maintainable code.

That is very simple math. Try to see if you can come up with something more complex(You should tell the user that they can use a caculator.) Also in line 34 what if the answer is "1221" or somthing random like that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.