Asking the user if they want to play again [duplicate]

2024/11/8 6:31:08

Basically it's a guessing game and I have literally all the code except for the last part where it asks if the user wants to play again. how do I code that, I use a while loop correct?

heres my code:

import random
number=random.randint(1,1000)
count=1
guess= eval(input("Enter your guess between 1 and 1000 "))while guess !=number:
count+=1if guess > number + 10:print("Too high!")elif guess < number - 10:print("Too low!")elif guess > number:print("Getting warm but still high!")elif guess < number:print("Getting warm but still Low!")guess = eval(input("Try again "))
print("You rock! You guessed the number in" , count , "tries!")while guess == number:count=1again=str(input("Do you want to play again, type yes or no "))
if again == yes:

guess= eval(input("Enter your guess between 1 and 1000 "))

if again == no:
break
Answer

One big while loop around the whole program

import randomplay = Truewhile play:number=random.randint(1,1000)count=1guess= eval(input("Enter your guess between 1 and 1000 "))while guess !=number:count+=1if guess > number + 10:print("Too high!")elif guess < number - 10:print("Too low!")elif guess > number:print("Getting warm but still high!")elif guess < number:print("Getting warm but still Low!")guess = eval(input("Try again "))print("You rock! You guessed the number in" , count , "tries!")count=1again=str(input("Do you want to play again, type yes or no "))if again == "no":play = False
https://en.xdnf.cn/q/120646.html

Related Q&A

IF statement (checking for a string in a list) behave weirdly [duplicate]

This question already has answers here:How to test multiple variables for equality against a single value?(31 answers)Closed 10 years ago.This will probably be a dumb question, but why does this piece…

filteration in txt file in python

I have too many lines like this:>ENSG00000100206|ENST00000216024|DMC1|2371|38568257;38570043|38568289;38570286 CTCAGACGTCGGGCCGACGCAAGGCCACGCGCGCGAACACACAGGTGCGGCCCCGGGCCA CACGCACACCGTACAC >ENSG0…

Count the number of times elements in a numpy array consecutively satisfy a condition

I have a numpy array as follows:import numpy as np a = np.array([1, 4, 2, 6, 4, 4, 6, 2, 7, 6, 2, 8, 9, 3, 6, 3, 4, 4, 5, 8])and a constant number b=6I am searching for a number c which is defined by t…

Finding the index of the first repeating item in an array in python

I was solving an arrays problem from GFG, where we need to find the index of the first repeating element. The question is as follows: Given an array arr[] of size n, find the first repeating element. T…

how to check str int list and tuple? [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

How to take out numbers and add them together in python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.Questions asking for code must demonstrate a minimal understanding of the problem being solved. Incl…

Populate mysql table with random data in python

How can create a mysql table in python and then populate it with random data.I want around 10000 rows and integer values will do work.

I want to change a tuple into string without joining it in python. How could I do that? [duplicate]

This question already has answers here:Convert a list to a string without join(5 answers)Closed 3 years ago.For Example: I want to change t=(a, b, c) to s=a, b, c

Convert several YAML files to CSV

I am very new to Python and have several YAML files that I need to convert into csv. These are notes, comments and emails that came from our CRM (Highrise). I ONLY need the Notes and Comments, not the …

Python split unicode characters and words

Im running a data science project and i need your help.My string is:string = 🎁Testand I expect that output:s1 = 🎁s2 = Test