新的stackflow,我希望我的问题可以帮助其他python新手。
我正在尝试创建一个执行以下操作的程序: 1. secret_num ==在1-10之间生成随机# 2.要求用户在1-10之间猜测这个数字 3.如果guess == secret_num祝贺他们并提供猜测的number_guesses数量(减去任何重复的猜测) 4.重复猜测的帐户 5.让他们知道猜测是否过高或过低
我知道这对你们很多人来说都是abc的东西,但我在语法,缩进和控制流方面遇到了典型的新程序员问题。现在我在elif guess == secret num上得到一个语法。否则我无法使用此代码来解决重复问题以挽救我的生命。我将不胜感激任何帮助。谢谢。
import random
def game():
# generate a random number between 1 -100 and initiate repeat guess list
secret_num=random.randint(1,10)
# initiate duplicate list and number of guesses
already_guesses = []
number_guesses = 0
while True:
# ask for user guess
guess = int(input('Guess a number from 1-10> '))
# help with guesses and announce if it is correct number!
# catch someone if they submit the same number
if guess in already_guesses:
print ("You already guessed that number, try again")
already_guesses.append(guess)
number_guesses += 1
elif guess == secret_num:
print("whooohoo! you guessed it, my number is {}".format(secret_num))
print("It took you {} guesses".format(number_guesses - len([already_guesses])))
break
elif guess < secret_num:
print("You\'re getting hot, try a higher number")
else:
guess > secret_num
print("You\'re cold, try a lower number")
# ask if they want to play again
else:
play_again = input("Do you wanna play again? y/n")
if play_again != 'n':
game()
else:
print("Bah Bye!")
game()
答案 0 :(得分:0)
您的代码还存在其他一些问题(在评论中提到缩进之后):
var exports = {};
importScripts('b64.js')
onmessage = function(e) {
var base64Bytes = fromByteArray(new Uint8Array(e.data));
postMessage(base64Bytes);
};