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
cupoosta [38]
3 years ago
8

Python Question: write a program that generates a random number in the range of 1 through 100, and asks the user to guess what t

he number is. If the user’s guess is higher that the random number the program should display "too high try again." If the user’s guess is lower than the random number, the program should display "too low,try again" If the user guesses the number the application should congratulate the user and then generate a new random number so the game can start over.
This is what I have so far..

#generates and imports a random number between 1-100
import random
number=random.randint(1,100)

#sets main function
def main():
print("This is a number guessing game.")
print("Guess what number we thought of between 1 and 100")
#print statement

num = number()
#stores number of user guesses
user = 0
#stores number of guesses
guesses = 0
#while statement
while user != num:

user=int(input("Enter your best guess!"))

guesses=guesses +1

if (user > num):
print ("Too high, try again")
else:
print("Congrats, you won!")
print("Restarting game")


main()
Computers and Technology
1 answer:
natima [27]3 years ago
6 0

Answer:

import random

arr=[]

for i in range(100):

   arr.append(i)

while True:

   answer=random.choice(arr)

   guess=int(input("enter your guess number between 0-100: "))

   if answer is guess:

       print("right guess\ncongratulations.....")

       print("the answer was: "+str(answer))

       break

   elif guess < answer-20:

       print("you guessed too low....\ntry again")

       print("the answer was: "+str(answer))

   elif guess > answer+20:

       print("you guessed too high....\ntry again")

       print("the answer was: "+str(answer))

   else:

       print("incorrect guess\ntry again")

       print("the answer was: "+str(answer))

Explanation:

You might be interested in
Which of the following statements is true?
nexus9112 [7]
Gray hat hacker work at a more advanced level then white and black hat hackers
3 0
3 years ago
Read 2 more answers
We have written a method called sum with an int[] parameter nums. We want our sum method to compute the sum of nums, but our cod
ira [324]

Answer:

Following are the code to this question:

public class Main//defining a class-main  

{

public static int sum(int[] nums)//defining a method sum that accepts array  

{

int total = 0;//defining integer variable total

for(int num : nums) // use for-each loop

{  

total += num;//add array value in total variable

}

return total;//use return keyword to return the total value

}

public static void main(String []ar )//defining a main method  

{

int[] nums={1,2,3,4,5};//defining 1-D array nums

System.out.println(sum(nums));//use print function to call sum method  

}

}

Output:

15

Explanation:

In the class "Main", a static method, "sum" is defined, that accepts array in its parameter and inside the method, an integer variable "total" is define, that uses the for each loop to add array value in a total variable and use a return keyword to return its value.  

Inside the main method, an integer array nums are defined, that holds store some values and use the print function to call the sum method.

8 0
3 years ago
Okay so remember that page I was advertising? At: fol ? Now it's deleted. And idk why because I was doing everything the right w
dimulka [17.4K]

Answer:

i don't think u can

Explanation:

maybe right a complaint or something

8 0
4 years ago
What is the most common type of communication?
tamaranim1 [39]

Answer:

technology texting

Explanation:

omega lol

6 0
3 years ago
.Pretend you are ready to buy a new computer for personal use.First, take a look at ads from various magazines and newspapers an
andriy [413]

Answer:

Brainly is not meant to give paragraph answers to large questions.

In a computer (desktop)

There are 8-9 main components to a PC

Motherboard

CPU

GPU (for gamers)

RAM

SSD

HDD

PSU

Cooling fans (for AMD processors stock fans are included)

Case (some fans included)

I personally build my computers (desktops) as its cheaper and I won't have to pay a build fee.

7 0
4 years ago
Other questions:
  • What is the name of the subsystem that transfers data between components inside a pc or between pcs?
    12·1 answer
  • Discuss some design considerations that you should keep in mind when you want to design a professional-looking flyer or newslett
    5·2 answers
  • Memory management is concerned with __________.
    14·1 answer
  • Which of the following is the formula used to calculate the risk that remains after you apply controls? a. ALE=SLExARO b. Total
    9·1 answer
  • write a program that reads in the length and the width of a rectangular yard . your program should compute the time required ( i
    5·1 answer
  • Select the correct answer.
    10·2 answers
  • Application servers are usually grouped into two types: page-based and _____ systems.
    6·1 answer
  • According to institutional anomie theory, why is there a need to maintain cooperation between economic and non-economic institut
    9·1 answer
  • Who is this wrong answers only
    7·1 answer
  • What is a use case of factorization in quantum computing?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!