target.py

Created by ews31415

Created on August 05, 2021

690 Bytes

The Python script target.py is a game where the player is tasked to guess a mystery number. The game has four levels:

Level 0: Easy. Range of 50, number between 100 and 999. Level 1: Medium. Range of 100, number is between 1,000 and 9,999. Level 2: Difficult. Range of 250, number is between 10,000 and 99,999. Level 3: Challenge. Range of 500, numbers if between 100,000 and 999,999.

After each guess you will be told whether the target is higher or lower than your guess. At the beginning you are given a range where your target number is.

Good luck!


from math import *
from random import *
# 2021-08-03 EWS
# target finding game

# set up
print("**** TARGET ****")
print(" EWS 2021")
print(" ")
print("SELECT MODE")
print("0. EASY")
print("1. MEDIUM")
print("2. DIFFICULT")
print("3. CHALLENGE")
c=int(input())

# variables
# range
r=50*c**2+50
# lower limit
x=10**(c+2)
# upper limit
y=10**(c+3)-1
# score
s=0
# target, limits
t=randint(x+r,y-r)
lx=t-r
ly=t+r

# the game
g=-1
print("The target is between")
print(str(lx)+" and "+str(ly)+".")

while g!=t:
  s+=1
  g=int(input("Guess "+str(s)+"? "))
  if g>t:
    print("LOWER")
  else:
    print("HIGHER")
  
print(str(g)+" is the target!")
print("Your score is: "+str(s))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.