Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

break issue

i wrote my own number game code but there is a problem in my break point in the try except part if my input is not an int it prints the message endless time if i put a break it send same message 1 time and quit the game couldn't solve how to print 1 time and move on to ask new number without any interruption.

while True :
try : guess == int(guess)
except ValueError: print("{} is not a number".format(guess)) #THİS PART! break
else: guesses.append(guess)
if len(guesses) == 5 : print("You are out of guess!") break elif guess != secret_num: print ("{} is Wrong".format(guess)) guess=input("make your guess between 1-100: ") continue elif guess == secret_num: print("Yeah {} is the corret one!".format (guess)) break else: print('You are out of guesses')

You need to format your code using the instructions provided in the markdown cheatsheet in the link right below the comment box. It says:

Code
Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.

          ```html
          <p>This is code!</p>
          ```

This way we can see how your code is actually formatted, without seeing that no one can tell you what's wrong.

3 Answers

Ismail KOÇ
Ismail KOÇ
1,748 Points
from random import randint
guesses=[]
secret_num = randint(1, 100)
print("i've got  a secret number try to find it")
guess=input("make your guess between 1-100: ")
guesses = []

while True :            
        try :
            guess == int(guess)            
        except ValueError:
            print("{} is not a number".format(guess)) 
            break

        else:
            guesses.append(guess)        
            if len(guesses) == 5 :
                print("You are out of guess!")
                break
            elif guess != secret_num:
                print ("{} is Wrong".format(guess))
                guess=input("make your guess between 1-100: ")
                continue
            elif guess == secret_num:
                print("Yeah {} is the corret one!".format (guess))
                break
else:
        print('You are out of guesses')     

your code is here ,(if you want write code in your comment, link, quotes or others look top of 'Post answer' and click Markdown Cheatsheet see how can do these.)

Look at your first mistake

guess == int(guess)

we uses == for equal (booleans, 1 or 0) you have to use for that =

Your second mistake

            elif guess == secret_num:
                print("Yeah {} is the corret one!".format (guess))

.format (guess) delete space between t and parantheses (format (guess) ---> format(guess)) (be careful for spaces you can add least 4 space (1 tab) and multiple (2,3,4) tab before statement, if you want add statement or something in another statement for ex:

for i in range(1,10)
    for j in range(15,65)
        print("{}, {}".format(i,j))      

)

and your last mistake

            elif guess == secret_num:
                print("Yeah {} is the corret one!".format (guess))
                break
else:
        print('You are out of guesses')     

there is no space before else, you have to add 3 tab space (12 space)

if you need help, do not hesitate and ask me.

thnax for that explanation(harika anlatmıssın anlıyorum bıde bu vıdyo serısının son letter game 2. bolumunde bı anda bam gum os sys gbı kavramlar gırıo pekde ne yaptıgını anlatmıyo onları nerden arastırabılırım hıc bı sey anlamadım yanı)

Ismail KOÇ
Ismail KOÇ
1,748 Points

thnax for that explanation(harika anlatmıssın anlıyorum bıde bu vıdyo serısının son letter game 2. bolumunde bı anda bam gum os sys gbı kavramlar gırıo pekde ne yaptıgını anlatmıyo onları nerden arastırabılırım hıc bı sey anlamadım yanı)

nothing (os sys kavramları biraz karışık oralara kafanı şimdilik pek takma sen döngüleri ve listeleri nasıl kullanabileceğine yoğunlaş çünkü bu işin devamında sana çok lazım olacak, diğer oynatma listelerine bakarak veya bu linke tıklayarak da bir şeyler bulabilirsin, kitabın indirme linkini burada bulabilirsin, ben indirdim fotokopiciden yazdırdım kitabı (kitab ayrıca açık kaynaklı olduğu için sıkıntı olmuyor) ve arada açıp bakıyorum(kitap biraz ağırdır, o kitabı araç olarak kullanmanı tavsiye ederim, bulabilirsen son baskısını indirmeye gayret et, kitap biraz kalın, kitabın ana kaynağında , python için bilgisayarına bir program indirmek istersen PyCharm programını tavsiye ederim (sen community sürümünü indir, ben professional olanı kullanıyorum (eğitim gördüğüm kurum site ile anlaşmalı olduğu için öğrenci lisansına sahibim bununla ilgili bir sorun olursa sor)), onu kurarsan ve sorun oluşursa bana danışırsın, ya da yeni soru sorarsın ve görebilirsem sana dönerim, şimdilik benden bu kadar çalışmaya devam et, ben senden biraz ilerdeyim, daha öğreneceğin çok şey var, başarılar diliyorum.)

(İstihza sitesi kapatılmış, Python 3 pdf dosyası bu linkte Python 2 pdf dosyası bu linkte)

but im on python.Didn't understand whats your saying ?

Right I was copying and pasting the example provided in the Markdown Cheatsheet, which is located right below the box you type your comment into. So replace html with python...

Ismail KOÇ
Ismail KOÇ
1,748 Points

Code Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.

      ```(only write python, html,... without parentheses)
      <p>This is code!</p>
      ```

kodunu bir de bu şekilde yazmayı dene, öbür türlü python boşluğa karşı duyarlı bir dil olduğu için kodunu kontrol etmem zorlaşıyor.

Ismail KOÇ
Ismail KOÇ
1,748 Points

i have checked your code and your code seems like has problem and i will try repair, just be careful for how much blanks in your code before write statements, if you need help do not hesitate and ask it to me. (Kodunu kontrol ettim ve bir sıkıntı var ve kodunu düzelteceğim, kodu yazarken doğru miktarda ifadeden önce doğru miktarda boşluk koyduğuna emin ol, soracağın bir şey olursa bana sorabilirsin)