【解決方法】数を推測する Python プロジェクト

プログラミングQA


こんにちは、私は Guess the Number Python Project に取り組んでおり、提供されたサンプル コードが正しいかどうかを知りたいです。 このソースコードは techgeekbuzz( 2022 年のソースコード付きのクールで楽しく簡単な Python プロジェクト[Updated][^] このpythonプロジェクトでは、乱数を生成したいのですが、ユーザーは3回しか推測できません。 ユーザーが試行するたびに、ユーザーが回答にどの程度近づいているかについてのポップアップ メッセージが表示されます。ユーザーがすべてのチャンスを完了した場合、システムは正しい回答を表示します。 それが正しいか、または数推測プロジェクトの他のソースコードを提供しているかどうか、誰か教えてもらえますか?

私が試したこと:

Python
import random #bring in the random number
import time
number=random.randint(1, 200) #pick the number between 1 and 200

def intro():
    print("May I ask you for your name?")
    name=input() #asks for the name
    print(name + ", we are going to play a game. I am thinking of a number between 1 and 200")
    time.sleep(.5)
    print("Go ahead. Guess!")

def pick():
    guessesTaken = 0
    while guessesTaken < 6: #if the number of guesses is less than 6
        time.sleep(.25)
        enter=input("Guess: ") #inserts the place to enter guess
        try: #check if a number was entered
            guess = int(enter) #stores the guess as an integer instead of a string    

            if guess<=200 and guess>=1: #if they are in range
                guessesTaken=guessesTaken+1 #adds one guess each time the player is wrong
                if guessesTaken<6:
                    if guess<number:
                        print("The guess of the number that you have entered is too low")
                    if guess>number:
                        print("The guess of the number that you have entered is too high")
                    if guess != number:
                        time.sleep(.5)
                        print("Try Again!")
                if guess==number:
                    break #if the guess is right, then we are going to jump out of the while block
            if guess>200 or guess<1: #if they aren't in the range
                print("Silly Goose! That number isn't in the range!")
                time.sleep(.25)
                print("Please enter a number between 1 and 200")

        except: #if a number wasn't entered
            print("I don't think that "+enter+" is a number. Sorry")
            
    if guess == number:
        guessesTaken = str(guessesTaken)
        print('Good job, ' + name + '! You guessed my number in ' + guessesTaken + ' guesses!')

    if guess != number:
        print('Nope. The number I was thinking of was ' + str(number))

playagain="yes"
while playagain=="yes" or playagain=="y" or playagain=="Yes":
    intro()
    pick()
    print("Do you want to play again?")
    playagain=input() 

解決策 1

私たちは立ち往生している人々を喜んで助けますが、それは私たちがあなたのためにすべてをするためにここにいるという意味ではありません! 私たちがすべての作業を行うことはできません。あなたはこれに対して報酬を受け取っているか、またはそれはあなたの成績の一部であり、私たちがあなたのためにすべてを行うことはまったく公平ではありません.

また、私たちは、あなたが計画しているコードが、あなた自身の作業が割り当てに合っているかどうかを確認するためにここにいるわけではありません。 インターネットでコードを見つけるだけでは開発ではなく、学習でもありません。宿題はそのために設定されています。

だから私たちはあなたが仕事をする必要があり、あなたが行き詰まったときにあなたを助けます. それは、あなたが提出できる段階的な解決策を提供するという意味ではありません!
現在の状況と、プロセスの次のステップを説明することから始めます。 次に、その次のステップを機能させるために何を試みたか、またその際に何が起こったかを教えてください。

開始するのに問題がある場合は、これが役立つ場合があります。 問題を解決するためのコードの書き方、初心者向けガイド[^]

コメント

タイトルとURLをコピーしました