I want to make a Guess the number code without input

2024/11/18 0:43:00
import random
number = random.randint(1, 10)player_name = "doo"
number_of_guesses = 0
print('I\'m glad to meet you! {} \nLet\'s play a game with you, I will think a number between 1 and 10 then you will guess, alright? \nDon\'t forget! You have only 3 chances so guess:'.format(player_name))while number_of_guesses < 3:guess = int(input())number_of_guesses += 1if guess < number:print('Your estimate is too low, go up a little!')if guess > number:print('Your estimate is too high, go down a bit!')if guess == number:break
if guess == number:print( 'Congratulations {}, you guessed the number in {} tries!'.format(player_name, number_of_guesses))
else:print('Close but no cigar, you couldn\'t guess the number. \nWell, the number was {}.'.format(number))

Above is the Guess the number project using input.

I want to make it without input.

Can't we use a list or variable to make it?

So I tried.

import random
list=[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")

Failed to create Guess the number code without input.

Help me.

Answer

As i understand, you want to "test" your program and therefore use a list of inputs instead of real user inputs?

However, you made a mistake in line 6 for number in lis: -> for number in list:

If I change this line it gives me this output. Is that what you wanted?

I am Guessing a number between 1 and 10:Your guess number is high 9
Your guess number is high 7
Your guess number is high 8
Sorry your chances of guessing is over! You can not guess the number correct
You guess Right The number is: 2
Number of guess taken 1
Your guess number is high 10
You guess Right The number is: 3
Number of guess taken 2
Your guess number is high 9
Your guess number is low 1
Your guess number is low 2
Sorry your chances of guessing is over! You can not guess the number correct
Your guess number is low 2
Your guess number is high 10
Your guess number is high 6
Sorry your chances of guessing is over! You can not guess the number correct
You guess Right The number is: 8
Number of guess taken 1
Your guess number is high 10
Your guess number is low 7
Your guess number is low 2
Sorry your chances of guessing is over! You can not guess the number correct
Your guess number is low 7
Your guess number is low 8
Your guess number is low 8
Sorry your chances of guessing is over! You can not guess the number correct
https://en.xdnf.cn/q/120136.html

Related Q&A

How to zip keys within a list of dicts

I have this object: dvalues = [{column: Environment, parse_type: iter, values: [AirportEnclosed, Bus, MotorwayServiceStation]}, {column: Frame Type, parse_type: list, values: [All]}]I want a zipped out…

AttributeError: DataFrame object has no attribute allah1__27

Im trying to solve this and Im pretty sure the code is right but it keeps getting me the same Error.I have tried this:import datetime from datetime import datetime as datettest_df = shapefile.copy() te…

How to convert csv to dictionary of dictionaries in python?

I have a CSV file shown below.I need to convert CSV to dictionary of dictionaries using python.userId movieId rating 1 16 4 1 24 1.5 2 32 4 2 47 4 2 …

Mo Money- Making an algorithm to solve two variable algebra problems

A cash drawer contains 160 bills, all 10s and 50s. The total value ofthe 10s and 50s is $1,760.How many of each type of bill are in the drawer? You can figure thisout by trial and error (or by doing a…

How to explode Python Pandas Dataframe and merge strings from other dataframe?

Dataframe1 has a lot of rows and columns of data. One column is Text. Certain rows in Text column have strings and some strings include within the strings this {ExplodeEList2} How to explode (expand) t…

Creating a new column with numbers in Pandas to group with a column with existing numbers

Good day, I have a column from a data frame here:A231011 22My objective is to create a new column and associate the numbers like this:A file_number 23 8 10 6 11 6 22 8As…

How to get PDF file from the binary data of SoftLayers quote?

I got the binary data by "getPdf" method of SoftLayers API.Ref. BillingSoftLayer_Billing_Order_Quote::getPdf | SoftLayer Development Network - http://sldn.softlayer.com/reference/services/Sof…

How to list of elements and use those elements as a header of pandas dataframe?

I have a list with some elements. For example: list= [name, phone_number,age,gender] I want to use these elements as a header or column name in a pandas dataframe. I would really appreciate your ideas.…

Averaging Filter using python

I am new in python and trying apply averaging filter on image as the way i understand averaging concept summing up the neighboring elements including itself and divide it by number of elementstechnique…

Click on Show more deals in webpage with Selenium

Id like to click on every Show 10 more deals on the following page: "https://www.uswitch.com/broadband/compare/deals_and_offers/" but it does not seem to work. Im stuck having the following e…