Reputation: 5
Here is the Pseudocode
I don't even know where to begin.
Upvotes: 0
Views: 15729
Reputation: 1
from random import randint
import time
print '='*20
print 'The Up / Down Game'
print 'Enter up or down !'
print 'Get 10 in a row for a reward!'
print '='*20
print "= "+'GAME START'+" ="
print '='*20
print ''
ans = ' '
score = 0
while True:
n1 = randint(2,13)
n2 = randint(2,13)
print "I have = %s" % (n1)
ans = raw_input("What do you choose: ")
if ans == 'up':
print "Your number is : "
time.sleep(0.5)
print "."
time.sleep(0.5)
print ". %s" % (n2)
time.sleep(1)
if n1 > n2:
print "Sorry you lost."
time.sleep(2)
print "Final score = %s" % (score)
time.sleep(2)
print "="*20
print "Try Again"
print "="*20
score = 0
elif n1 <= n2:
score += 1
if score > 1:
print "That's %s in a row" % (score)
elif score == 1:
print "Thats 1 point"
elif score == 10:
print "Congratz you got the reward!!!"
elif ans == 'down':
print "Your number is : "
time.sleep(0.5)
print "."
time.sleep(0.5)
print ". %s" % (n2)
time.sleep(1)
if n1 < n2:
print "Sorry you lost."
time.sleep(2)
print "Final score = %s" % (score)
time.sleep(2)
print "="*20
print "Try Again"
print "="*20
score = 0
elif n1 >= n2:
score += 1
if score > 1:
print "That's %s in a row" % (score)
elif score == 1:
print "Thats 1 point"
elif score == 10:
print "Congratz. You got the reward"
else:
tryAgain = raw_input("enter up or down only")
Upvotes: -1
Reputation: 9
print ("*********** Hi Lo Game ***********")
import random
x = (random.randint(1,100))
num1 = int(input("Enter your number:"))
while num1 < x:
print ("Too Low")
num1 = int(input("Enter your number:"))
while num1 > x:
print ("Too High")
num1 = int(input("Enter your number:"))
if num1 == x:
print ("Congratulations! You are Correct")
Upvotes: 0
Reputation: 881653
Here's where you begin. Insert the specifications as documentation, then do one at a time, testing along the way.
# Print instructions to the user
### 'print "xyz"' will output the xyz text.
# Start with the variables high = 1000, low = 1, and tries = 1
### You can set a variable with 'abc = 1'.
# While high is greater than low
### Python has a while statement and you can use something like 'while x > 7:'.
### Conditions like 'x > 7', 'guess == number' can also be used in `ifs` below.
# Guess the average of high and low
### The average of two numbers is (x + y) / 2.
# Ask the user to respond to the guess
### Python (at least 2.7) has a 'raw_input' for this, NOT 'input'.
# If the guess was right, print a message that tries guesses were required
# and quit the program
### Look at the 'if' statement for this and all the ones below.
# If the guess was too high, print a message that says “I will guess lower.”
# If the guess was too low, print a message that says “I will guess higher.”
# If the user entered an incorrect value, print out the instructions again.
I've also added a small comment detailing what language elements you should look in to for each section.
Upvotes: 2
Reputation:
Ok, this isn't the answer but you need to look at the program:
Pseudo Code:
print "intructions"
thenumber = rand() % 1000+1
while (true)
getInput(guess);
if (guess > thenumber)
print "Guess lower"
else if (guess < thenumber)
print "Guess higher")
else
exit //or break.
Just pseudo code though.
Upvotes: 0
Reputation: 881853
You begin with point one:
print "instructions to the user"
(just change the string to be more informative, that's not a programming problem!-), then continue with point two (three assignments, just like your homework assignment says), then with point three:
while high > low:
There -- that's half your work already (points 1-3 out of 6). What's giving you problems beyond that? Do you know what average means, so (say) guess = (high + low) // 2
is understandable to you, or what? That's all you need for point 4! Do you know how to ask the user a question and get their response? Look up input
and raw_input
... OK, I've covered the first five of the six points, surely you can at least "get started" now!-)
Upvotes: 0
Reputation: 18590
You don't say if this is Python 2 or 3. The following should be good for recent versions of 2; I'm not familiar with 3, but it will probably at least get you started there too. Seeing as how this is homework, I'm just going to recommend some things for you to research.
Upvotes: 0