How to fix Python restarting whenever I start program on IDLE environment?

2024/11/17 7:18:43
import randomwinning_conditon = 0
no_of_guesses = 0
comp_guess = random.randint(1,100)while (no_of_guesses == 11) or (winning_conditon == 1):user_guess = int(input("What is your guess? "))if user_guess < 1 or user_guess > 100:print("Your number is invalid!")elif comp_guess == user_guess:print("Well Done!")winning_condition = 1elif comp_guess < user_guess:print("Your number is too high!")elif comp_guess > user_guess:print("Your number is too low!")no_of_guesses = no_of_guesses + 1print(no_of_guesses)
print("You haven't guessed the right amount of times or u won.")

Whenever I start python IDLE (i am using Portable Python 3.2.5.1 (http://portablepython.com/wiki/PortablePython3.2.5.1/)) it comes up with a restart message and then it displays an "=" sign and doesn't continue the program. Do you know a fix?

Answer

When I run your program I get this output:

Python 3.2.5 (default, May 15 2013, 23:06:03) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
You haven't guessed the right amount of times or u won.
>>> 

This is perfectly fine and expected.

I would modify your program this way:

while not (no_of_guesses == 11 or winning_conditon == 1)

while not would be the equivalent of until.

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

Related Q&A

Fetching Lawyers details from a set of urls using bs4 in python

I am an absolute beginner to Web Scraping using Python and know very little about programming in Python. I am just trying to extract the information of the lawyers in the Tennessee location. In the web…

Having trouble with python simple code running in console [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

.upper not working in python

I currently have this codenum_lines = int(input()) lines = [] tempy = ctr = 1 abc = {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z } for i in range(0, num_lines):tempy = input()lines.append([])l…

Python SKlearn fit method not working

Im working on a project using Python(3.6) and Sklearn.I have done classifications but when I try to apply it for reshaping in order to use it with fit method of sklearn it returns an error. Heres what …

extracting n grams from huge text

For example we have following text:"Spark is a framework for writing fast, distributed programs. Sparksolves similar problems as Hadoop MapReduce does but with a fastin-memory approach and a clean…

Python: Input validate with string length

Ok so i need to ensure that a phone number length is correct. I came up with this but get a syntax error.phone = int(input("Please enter the customers Phone Number.")) if len(str(phone)) == 1…

Mergesort Python implementation

I have seen a lot of mergesort Python implementation and I came up with the following code. The general logic is working fine, but it is not returning the right results. How can I fix it? Code: def me…

Use variable in different class [duplicate]

This question already has answers here:How to access variables from different classes in tkinter?(2 answers)Closed 7 years ago.I am a beginner in python. I have a problem with using variable in differ…

Embedded function returns None

My function returns None. I have checked to make sure all the operations are correct, and that I have a return statement for each function.def parameter_function(principal, annual_interest_rate, durati…

calculate days between several dates in python

I have a file with a thousand lines. Theres 12 different dates in a single row. Im looking for two conditions. First: It should analyze row by row. For every row, it should check only for the dates bet…