Write a program to play a guessing game using random module?



Write a program to play a guessing game using random module?..

Answer / Mayank Tripathi

To create a simple number-guessing game using the `random` module, you can generate a random number and ask the user to guess it. Here's an example:n```pythonnimport randomnsecret_number = random.randint(1, 20)n# Ask for user input until they guess correctlynwhile True:n guess = int(input('Guess a number between 1 and 20: '))n if guess == secret_number:n print('Congratulations! You guessed the number.')n breakn else:n print('Sorry, that is not correct. Try again.')```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

Python or r: which one would you prefer for text analytics?

1 Answers  


Which method removes and returns last object of a list?

1 Answers  


What does means by split do in python?

1 Answers  


Is python as powerful as c++?

1 Answers  


How useful is python?

1 Answers  


Write a program structure in python?

1 Answers  


Does python have private variables?

1 Answers  


Explain Inheritance in Python?

1 Answers  


is there any maximum length expected for an identifier?

1 Answers  


Differentiate list and tuple with an example?

1 Answers  


What is python rest api?

1 Answers  


What is the difference between and ?

1 Answers  


Categories