这是Pseudocode
我甚至不知道从哪里开始。
答案 0 :(得分:2)
这是你开始的地方。将规范作为文档插入,然后一次一个地进行测试。
# 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.
我还添加了一个小评论,详细说明了每个部分应该查看哪些语言元素。
答案 1 :(得分:0)
你没有说这是不是Python 2或3.以下应该适用于2的最新版本;我不熟悉3,但它可能至少会让你从那里开始。看到这是如何做作业,我只是建议你研究一些东西。
答案 2 :(得分:0)
从第一点开始:
print "instructions to the user"
(只是更改字符串以提供更多信息,这不是编程问题! - ),然后继续第二点(三个作业,就像您的作业分配所说),然后是第三点:
while high > low:
那里 - 已经有一半的工作(6分中的1-3分)。除此之外,还有什么问题?你知道 average 意味着什么,所以(比方说)guess = (high + low) // 2
对你来说是可以理解的,或者是什么?这就是第4点所需要的!您知道如何向用户询问问题并获得他们的回复吗?查看input
和raw_input
...好吧,我已经涵盖了六点中的第一个五,当然你可以至少“开始“现在! - )
答案 3 :(得分:0)
好的,这不是答案,但您需要查看该程序:
伪代码:
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.
虽然只是伪代码。
答案 4 :(得分:0)
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")
答案 5 :(得分:-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")