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
notsponge [240]
3 years ago
13

Write a simple number guessing game Python program. In this code, generate a random integer between 1-10 (both included) and ask

the user to guess the number in three attempts. Print appropriate responses to the user such as "You won!" or "You failed"
Computers and Technology
1 answer:
seraphim [82]3 years ago
6 0

Answer:

from random import randint

num = randint(1,10)

count =0

while count<3:

 userNum = int(input("Guess a Number "))

 if num ==userNum:

   print("You won")

   break

 else:

   print("Wrong try again")

 count = count+1

Explanation:

Import randint from random

generate a random number between (1,10) and assign to num

create a loop control variable count set to 0

In a While statement with the condition count<3 prompt user to make a guess

if guess is correct print you won and break

else print wrong try again and increase count by 1

You might be interested in
Ask the user how many high scores they want.
Alex

Answer:

Check the explanation

Explanation:

As per requirement submitted above kindly find below solution.

Here new console application in C# is created using visual studio 2019 with name "HighScoreApp". This application contains a class with name "Program.cs".Below is the details of this class.

Program.cs :

//namespace

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

//application namespace

namespace HighScoreApp

{

class Program //C# class

{

//entry point of the program , Main() method

static void Main(string[] args)

{

//declaring variable to store number of score

int numberOfScores = 0;

//using while loop

while(numberOfScores<=0)

{

//asking user number of high scores

Console.WriteLine("Enter number of high scores : ");

//reading input

numberOfScores = int.Parse(Console.ReadLine());

}

//declaring array with number of scores

int[] scores = new int[numberOfScores];

//asking user high scores using for loop

for (int i = 0; i < scores.Length; i++)

{

//asking high scores

Console.WriteLine("Enter score "+(i+1)+" : ");

//reading score

scores[i] = int.Parse(Console.ReadLine());

}

Console.WriteLine();//used for new line

Console.WriteLine("High Scores -Unsorted");

//call function to print each element

PrintArray(scores);

//call method to sort the array elements

scores = SortArrayHighToLow(scores);

Console.WriteLine();//used to print new line

Console.WriteLine("High Scores-Sorted");

PrintArray(scores);//call method to print array elements

Console.SetCursorPosition(0, Console.WindowHeight - 1);

Console.WriteLine("Press ENTER to continue....");

Console.ReadLine();

}

//method to print the array

public static void PrintArray(int [] scoresArray)

{

//using for loop , print each score

for (int i = 0; i < scoresArray.Length; i++)

{

Console.WriteLine(scoresArray[i]);//print each high score

}

}

//method to sort the array

public static int [] SortArrayHighToLow(int[] scoresArray)

{

Array.Sort(scoresArray);

return scoresArray;

}

}

}

==================================

Output :Run application using F5 and will get the screen as shown below

Kindly check the below Screenshot for Output :Program.cs

6 0
3 years ago
What is similar software engineering, Hardware engineer, Network Architect, and Web developer?
Oliga [24]

I Am Pretty Sure The Answer Is - "B"

Hope This Help's

5 0
3 years ago
What are some of the challenges that could arise from setting up a file management system on a computer?
erastovalidia [21]
One challenge is that arranging things in simple folders creates a limited structure that obstructs the way that would perfectly suit your needs. Any information that is dependent on those folders can easily get lost by removing as much as a simple image from that folder, in the events that the information is dependent on the folder structure.
7 0
3 years ago
Peter is explaining the steps to create a fire effect in an image to his class. Help Peter pick the correct word to complete the
Pavel [41]

Answer:

The answer would be "Blending"

Explanation:

I took the test and checked over my answers

4 0
3 years ago
When google originally beta tested their search engine with the 16 students, what did the google team observe?
mrs_skeptik [129]
What's wrong with it and how to fix it mainly because there was bus I think
4 0
3 years ago
Other questions:
  • What are two reasons for using layered protocols? what is one possible disadvantage of using layered protocols?
    13·1 answer
  • add is a method that accepts two int arguments and returns their sum. Two int variables, euroSales and asiaSales, have already b
    11·1 answer
  • Consider the clipping of a line segment in two dimensions against a rectangular clipping window. Show that you require only the
    10·1 answer
  • What is the Matlab command to create a vector of the even whole numbers between 29 and 73?
    11·1 answer
  • If a firm's pages are not near the top of query results, customers may never discover its website. This has led to _____ becomin
    12·1 answer
  • Describe data center technology and its relevance to modern-day cloud computing
    14·1 answer
  • Why can a bank afford to pay an interest rate on a savings account?
    11·1 answer
  • What construction work is the tender for​
    10·2 answers
  • What component of a change management program includes final testing that the software functions properly
    11·1 answer
  • Which type of service offers a preconfigured testing environment for application developers to create new software applications?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!