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
‘The increased availability of mobile digital devices has had a positive impact on how young people use their free time’. Make a
Law Incorporation [45]
"The increased availability of mobile digital devices has had a positive impact on how young people use their free time."

There are many different views that you could take upon this subject.  

1) You could say that the increased availability of mobile digital devices has allowed children to increase their academic success, by being able to search for and complete assignments using these devices.

2) You could say that the increased availability of mobile digital devices allows for children to occupy themselves by providing games, videos, books, and other things to provide them with entertainment, a learning experience, and more.

Hope this helps!
4 0
3 years ago
What can be controlled through IoT? Choose four answers.
Maru [420]

<em>The answer is: </em>

<em> </em>

<em>Door locks, light switches, security cameras and desktops (even laptops too) </em>

<em> </em>

<em>When we say Internet of Things, it is basically all objects that can be connected to internet (objects that are parts of our daily lives) can be included in this phrase or quote). There are technologies pertaining to common household items such as locks, switches and cameras that can be controlled through the use of phones and internet. These things collect and stores data such as names, fingerprints, pictures and scans that are used for verification and authentication purposes. </em>

<em> </em>

<em />

5 0
3 years ago
Latent data is which of the following?
Levart [38]
Generally invisible to the user, like you can't see it on your OS or in just a standard application
8 0
3 years ago
Read 2 more answers
If you fail a course as a MAIN (residency) course, you can repeat that course as either a MAIN (residency) or an online (IG or I
Elina [12.6K]

Answer: False

Explanation:

The statement that "you fail a course as a MAIN (residency) course, you can repeat that course as either a MAIN (residency) or an online (IG or IIG) course" is false.

It should be noted that if one fail a course as a residency course, the course can only be repeated as a main (residency) course and not an online course. When a course is failed, such course has to be repeated the following semester and this will give the person the chance to improve their GPA.

5 0
3 years ago
___refers to self-acting or self-operating.
lisabon 2012 [21]

Answer:

do it to me watch this

Explanation:

trailing zeros in a whole number with no decimal shown are NOT significan

6 0
4 years ago
Other questions:
  • True or False: if there are multiple operations inside a parentheses, you do not need to complete theses in the order of pemdas​
    12·1 answer
  • Convert to binary140
    5·1 answer
  • The Outline tab and the Slides tab can be open at the same time.
    7·1 answer
  • a_____________ may have its value change during program execution. options. flowchart,counter, Algorithm,None of them​
    15·1 answer
  • You’ve found the file you’ll be working with. Next, you decide to move the file to your Desktop so it will be easier to get to i
    14·1 answer
  • Expalin the defference between the driver of a desktop and a laptop​
    8·1 answer
  • Explain why microcomputers are installed with TCP/IP protocols?​
    15·1 answer
  • What are all the Answer Streaks (Fun Facts) for brainly?
    13·2 answers
  • 3. When code tracing, why is it important to iteratively test parts of the program?
    8·1 answer
  • If a student ate 3/4 (three-fourths) of their meals away from home, what % of the total day is spent eating other than at home?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!