I want to complete the quiz with variables or lists without Python input

2024/11/15 20:02:39
import random
number = random.randint(1, 10)player_name = input("Hello, What's your name?")
number_of_guesses = 0
print('okay! '+ player_name+ ' I am Guessing a number between 1 and 10:')while number_of_guesses < 5:
guess = int(input())
number_of_guesses += 1`if guess < number:print('Your guess is too low')if guess > number:print('Your guess is too high')if guess == number:break
if guess == number:print('You guessed the number in ' + str(number_of_guesses) + ' tries!')
else:print('You did not guess the number, The number was ' + str(number))

Above is the normal Python Numberguessing game code.

But I want to make a quiz game using variables or lists without input.

Like using input

import random
number = random.randint(1, 10)list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]number_of_guesses = 0
print(' I am Guessing a number between 1 and 10:')while number_of_guesses < 3:number_of_guesses += 1if list < number:print('Your guess is too low')if list  > number:print('Your guess is too high')if list  == number:break
if list  == number:print('축하합니다! 당신은 {}번의 시도만에 정답을 맞췄습니다.!'.format(number_of_guesses))                  
else:print('아쉽지만 정답을 맞추지 못했네요. 정답은 {} 이었습니다. 다시 도전해보세요!'.format(number))

I tried to make it using a list or variable, but I failed. Help me please.**

Answer

See my code 👇.

Code-:

import random
lis=[1, 2, 3, 4, 5, 8, 9, 10]
print('I am Guessing a number between 1 and 10:\n')
for number in lis:number_of_guesses = 0while number_of_guesses<3:guess_number=random.randint(1,10)if number<guess_number:number_of_guesses+=1print('Your guess number is high '+str(guess_number))elif number>guess_number:number_of_guesses+=1print('Your guess number is low '+str(guess_number))else:print("You guess Right The number is: "+str(guess_number)+"\nNumber of guess taken "+str(number_of_guesses+1))breakif number_of_guesses==3:print("Sorry your chances of guessing is over! You can not guess the number correct")

Output:-

I am Guessing a number between 1 and 10:Your guess number is high 5
Your guess number is high 10
Your guess number is high 9
Sorry your chances of guessing is over! You can not guess the number correct
Your guess number is high 4
Your guess number is high 7
Your guess number is high 3
Sorry your chances of guessing is over! You can not guess the number correct
Your guess number is high 5
Your guess number is high 5
Your guess number is high 10
Sorry your chances of guessing is over! You can not guess the number correct
Your guess number is high 5
Your guess number is high 8
Your guess number is high 6
Sorry your chances of guessing is over! You can not guess the number correct
Your guess number is high 7
Your guess number is low 1
You guess Right The number is: 5
Number of guess taken 3
Your guess number is low 5
Your guess number is high 9
Your guess number is low 3
Sorry your chances of guessing is over! You can not guess the number correct
Your guess number is high 10
Your guess number is low 3
Your guess number is low 5
Sorry your chances of guessing is over! You can not guess the number correct
Your guess number is low 6
Your guess number is low 5
Your guess number is low 7
Sorry your chances of guessing is over! You can not guess the number

Please give the feedback if this helps to you..!

https://en.xdnf.cn/q/120414.html

Related Q&A

Comparing a list to a a list of tuples?

I have two lists. One is simply a list of idsids = [123, 124, 127, 316, 463]and the other is a list of tuples of ids and namescombined = [(123, "Brian"), (124,"Eric"), (222,"Ja…

Sum from 1 to n, 2 to n, ... n in python

I was trying to get a series of sum from 1 to n, 2 to n, ..., and nFor example, if n=5, then the result should be 15 14 12 9 5Please comment for the code below. I cant figure out whats wrong.n=int(inpu…

How do I scrape the about section of a Facebook page? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 6…

How can I dynamically create a name of a variable in Python? [duplicate]

This question already has answers here:How do I create variable variables?(18 answers)Closed 6 years ago.I am having a function in pythondef func(dataFrame,country,sex):varible_name=dataFrame[(dataFra…

Why are Python dictionaries NOT stored in the order they were created? [duplicate]

This question already has answers here:Why is the order in dictionaries and sets arbitrary?(5 answers)Closed 8 years ago.Just curious more than anything else, but why isnt a dictionary such as the one…

How to extract out a non-continuous matrix from a larger matrix based on a list [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 2…

Python get info from long complicated string

Im trying to get info from strings that I have parsed. Im trying to get the font size. This is the string Im returning style="fill: rgb(0, 0, 0); fill-opacity: 1; font-family: ProjectStocksFont; f…

How can i ask for user input and use that input for this text summarizer i created? [duplicate]

This question already has answers here:How do I read from stdin?(25 answers)Closed last year.I have created a text summarizer based on a code I found on Github. Im trying to have to script ask for the…

Return to main menu function for python calculator program

I was asked to write a calculator in Python, and I completed it, but there is only one issue that needs to be fixed. What is the prerequisite? "Once the user inputs/selects an arithmetic operatio…

what the code to use in # Complete this function with recursion in lines 4

# TODO: 2. Create a function that counts the sum of all the numbers in a list belownumber = [1,2,3,4,5] # Use this list as inputdef hitung_total(listKu):# Complete this function with recursionreturn li…