1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
LenKa [72]
3 years ago
13

In this lab, you will write a function called numberGuessingGame(). When the function is called, it will do the following: gener

ate a random integer between 1 and 10 (you will need to import and use the random library) allow user 3 chances to guess the number if the user guessed the correct number, print out "You guessed it!" and ends the game otherwise if user made an incorrect guess, print out "Incorrect!" it will compare the guess with the generated random number, and if the guess is smaller, print out a hint message "You guessed too low"; else if the guess is larger, print out a hint message "You guessed too high" reduce the chance by one printout how many chances are left if user has not used up the chances, ask the user to guess the number If user used up the three chances, print "You lost! The number is [number]". Game ends Sample output: >>> numberGuessingGame() Guess a number between 1 and 10: 8 You guessed too high You have 2 chances left. Guess a number between 1 and 10: 4 You guessed too high You have 1 chances left. Guess a number between 1 and 10: 3 You guessed too high You have 0 chances left. You lost! The number is 1 Check Point Thoroughly test your program and make sure your program works. Submit your python code as .py file in text format, and capture the screens of your program running showing multiple input and output.
Computers and Technology
1 answer:
Kobotan [32]3 years ago
8 0

Answer:

#here is code in Python

# import library

import random

#function

def numberGuessingGame():

   # generate random number between 1-10

   num = random.randint(1,10)

   no_of_g = 3

 #loop to check the guess

   for i in range(no_of_g):

       #read inout number from user

       inp_num = int(input("Guess a number between 1-10:"))

       #check input is less than random number

       if inp_num < num:

           print("Your guess is too low")

           print("", 2-i, "chances left.")

           continue

       #check input is greater than random number

       elif inp_num > num:

           print("Your guess is too high")

           print("", 2-i, "chances left.")

           continue

       #check input is Equal random number

       else:

           print("You won!")

           print("The number is", num)

           break

   #if chances are Equal to 0

   if not (num == inp_num):

       print("You lost!")

       print("The number is", num)

#call the function

numberGuessingGame()

Explanation:

Generate a random number between 1-10.Then ask user to enter a number.If user's input is greater than random number then print "too high".If number is less than random number then print "too low".If user's input is equal to random number then print "You won!" and random number in new line. This will repeat for 3 time.If user is not able to guess the random number for 3 times then it will print "You lost!" and the random number.

Output:

Guess a number between 1-10:5

too high

2 chances left.

Guess a number between 1-10:6

too high

1 chances left.

Guess a number between 1-10:1

too low

0 chances left.

You lost!

The number is 3

You might be interested in
Alex is setting up a network for his company's computers. He installs a circuit board into each computer, enabling it to be conn
Nitella [24]
If it's an ethernet network:  <span>network interface card</span>
6 0
3 years ago
this email belongs to another account. enter a different account. does this mean my brainly account can only use one device and
azamat

Answer:

I believe it is saying your login credentials are somehow incorrect otherwise you should be able to log into many devices

Explanation:

5 0
3 years ago
Read 2 more answers
Two technicians are discussing engine valve timing. Technician A says that the optimum valve timing is found through experimenta
nordsb [41]
The answer is B. A only. The optimum valve timing is found through experimentation using an engine dynamometer. The timing of the opening and closing of the valves is called valve timing. So the use of dynamometer measures the power output of a machine that is why it can measure the optimum valve timing.
7 0
3 years ago
Read 2 more answers
Henry Ford would have been most interested to bring which modern innovation to his automotive factories?
kondor19780726 [428]
Henry Ford would have been most interested to bring assembly lines which is an modern innovation to his autmotive factories. Although Henry Ford didn't invent cars he developed assembly lines
3 0
3 years ago
Read 2 more answers
☢☢☢does anyone know how to do the TYNKER CANNON assignment ( lesson 2 intro to game design) I'll give BRANLIEST(¬‿¬)❤ dont answe
sleet_krkn [62]

Answer:

whats the question?

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • If a cheetah covers 155 meters in 5 seconds, at what speed is the cheetah running?
    14·2 answers
  • Write a calculator program that keeps track of a subtotal like real calculators do. Start by asking the user for an initial numb
    12·1 answer
  • Someone once observed that "the difference between roles and groups is that a user can shift into and out of roles, whereas that
    13·1 answer
  • &amp;. Give three differences between a<br>web browser<br>and web page​
    11·1 answer
  • Kathi, the owner of Klothes for Kats, is excited about the launch of her first Local Catalog ad. She remembers there are a few d
    6·1 answer
  • Que significa DESFRAGMENTAR EL DISCO DURO?????
    14·1 answer
  • Find true or false. A hacker is hacking software with access in sensitive information from your computer​
    9·1 answer
  • Which devices are likely to include a computer? Select 3 options.
    7·1 answer
  • During which phase of the writing process is it best to have other
    11·1 answer
  • Who would win in a fight, Noble 6 from halo reach or Master Chief??
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!