[ad_1]

Performance Assessment2.4 – Input, Output and Processing

Task 1 – Input from the user

Open the Python 3.10 Integrated Development Learning Environment (IDLE) and create a new project named, GuessNumber

Have the computer select a random number with the following commands:

from random import randint

                print(“<Your Student number>”)

                num = randint(1,9)

                user_guess = 0

 

Create a loop that will check to see if the user_guess is the same as the random number

 

                while user_guess != num:

 

Inside the loop get a guess from the user and check to see if the guess is lower than the number

                user_guess = int(input(“Enter a guess from 1 to 9: “))

if user_guess< num:

                                print(“Guess is low”)

                elifuser_guess> num:

                                print(“Guess is high”)

                else:

                                print(“You guessed it!”)

 

 

Keep running the program until you get one Guess is high, Guess is low, and you guessed it response.

 

Deliverables for Task 1

  • Screenshot of your GuessNumber program
  • Screenshot of the results of running your program.

 

Task 2 – Adding a counter

Now you will add a counter to keep track of the number of guesses.

Before your looping statement add a counter with

guess = 0

               

 

Add the counter statement inside the loop (before the if statements):

 

guess += 1

 

 

 

Change the winning statement to:

 

print(f”You guessed it!  You won in {guess} guesses!”)

 

Deliverables for Task 2

  • Screenshot of your GuessNumber program
  • Screenshot of the results of running your program.

 

[ad_2]

Testimonials

Python Scripting
We have updated our contact contact information. Text Us Or WhatsApp Us+1-(309) 295-6991