我已经尝试过一切我仍然无法工作的事情。请任何帮助将不胜感激。 请我能够允许它生成一个提示,但是我需要它来生成3个不同的提示3个不同的时间用户按0提示。 我有它提示甚至或奇怪。我需要它提供额外的2个提示。 第1部分:
第2部分:
到目前为止,这是我的计划:
import random
guessesTaken = 0
print('WELCOME! What is your name?')
myName = input()
number = random.randint(1, 100)
print('Hello, ' + myName + ', I generated a number between 1 and 100.')
unsuccessful_tries = 0
hint_taken = 0
while guessesTaken < 10:
if unsuccessful_tries > 1 and hint_taken<3:
print('Press 0 to get hint')
need_hint = int(input())
if need_hint == 0:
hint_taken += 1
guessesTaken += 1
if number%2==0:
print('The Generated number is an EVEN number')
else:
print('The Generated number is an ODD number')
print('Take a guess.\t%d Attempts Left'%(10 - guessesTaken))
#10-guessTaken gives the number of tries left
guess = input()
guess = int(guess)
#validating the user's input
if guess >100 or guess<0:
continue
guessesTaken = guessesTaken + 1
if guess < number:
print('Your guess is too low.')
if guess > number:
print('Your guess is too high.')
if guess == number:
break
unsuccessful_tries+=1
if guess == number:
guessesTaken = str(guessesTaken)
print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
if guess != number:
number = str(number)
print('Nope. The number I was thinking of was ' + number)
答案 0 :(得分:0)
让我轻推你解决第二部分:
您已经使用guessesTaken
变量跟踪用户猜测
随机提示&#39;可以简单地随机选择一个预先制定的提示列表(如果您有5个预先制定的提示,您可以选择1-5之间的随机数,并选择那个)
&#39;成本核算&#39;用户两次尝试是评估他们是否有足够的猜测来支付它(即:如果他们在第9次猜测,他们不能放弃2次猜测),然后如果他们接受,则向guessNumber添加两个提示。
这是我能给你的最准确的答案,因为你还没有为第2部分提供任何代码,或者你需要帮助。
点#2的松散示例:从列表中选择一个随机函数:
my_list = [func_test_1, func_test_2, func_test_3]
random.choice(my_list)()
答案 1 :(得分:0)
您应该创建变量来跟踪不成功的尝试次数和提示。如果不成功的尝试次数大于2并且提示的次数小于3,那么您应该询问用户是否需要提示。
import random
guessesTaken = 0
print('Hello! What is your name?')
myName = input()
number = random.randint(1, 100)
print('Hello, ' + myName + ', I am thinking of a number between 1 and 100.')
unsuccessful_tries = 0
hint_taken = 0
while guessesTaken < 10:
if unsuccessful_tries > 1 and hint_taken<3:
print('Press 0 to get hint')
need_hint = int(input())
if need_hint == 0:
hint_taken += 1
guessesTaken += 1
print('Here is hint')
#Do this by yourself chose a hint and display
print('Take a guess.\t%d Attempts Left'%(10 - guessesTaken))
#10-guessTaken gives the number of tries left
guess = input()
guess = int(guess)
#validating the user's input
if guess >100 or guess<0:
continue
guessesTaken = guessesTaken + 1
if guess < number:
print('Your guess is too low.')
if guess > number:
print('Your guess is too high.')
if guess == number:
break
unsuccessful_tries+=1
if guess == number:
guessesTaken = str(guessesTaken)
print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
if guess != number:
number = str(number)
print('Nope. The number I was thinking of was ' + number)