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
What is the procees called when deleting a hard drive securelly
zlopas [31]
The process of securely erasing a hard drive is called wiping :)
8 0
4 years ago
What type of program allows a user to copy or back up selected files or an entire hard disk to another storage medium?
nikdorinn [45]

Answer:

backup utility

Explanation:

7 0
3 years ago
A ________ is a virus that is attached to documents such as word or excel files.
Olin [163]
A macro virus is a specific type of virus wherein it attaches to word processing documents like MS Word or MS Excel files. Furthermore, this virus would launch commands wherein it automatically starts certain programs that consume a lot of you computer memory. However, it could just be easily removed by an anti-malware tool.
6 0
3 years ago
Which of the following is likely the cause of the bass from a sound system rattling the windows on your car?
Andrei [34K]
The vibration of the sound system
4 0
3 years ago
Sam’s password is known to be formed of 3 decimal digits (0-9) in a given order. Karren and Larry are attempting to determine Sa
prohojiy [21]

Answer:

100

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Can you help me correct a sentence?
    13·1 answer
  • What impact did congress declaration on copyrighting sound recordings have on home recording and record sales
    8·2 answers
  • Jason had clicked an image of his favorite band at a concert. He wanted to create a washed out look of this image to turn it int
    6·1 answer
  • What game is this??????????????????????
    12·1 answer
  • What is the full meaning of Internet and WiFi
    6·2 answers
  • Write a script that inputs a line of plaintext and a distance value and outputs an encrypted text using a Caesar cipher.
    15·1 answer
  • Why is my Brainly scanner not work​
    5·2 answers
  • If you cannot find a template on your computer that was appropriate for your task, what should you do?
    12·1 answer
  • What are the main approaches for dealing with deadlock?
    7·1 answer
  • ANSWER QUICKLY!!!
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!