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 Python Basics (2015) Logic in Python The Exception to the Rule

George Lugo
seal-mask
.a{fill-rule:evenodd;}techdegree
George Lugo
Python Web Development Techdegree Student 922 Points

im trying this on the workspace and it is still not working i do not understand why

im getting python can't open file no such file or directory for some weird reason

Steven Parker
Steven Parker
231,269 Points

To enable a specific and accurate analysis, always show your code (properly formatted, of course)! Even better, make a snapshot of your workspace and post the link to it here.

Formatting instructions can be found in the Markdown Cheatsheet pop-up below "Add an Answer" :arrow_heading_down:

4 Answers

George Lugo
seal-mask
.a{fill-rule:evenodd;}techdegree
George Lugo
Python Web Development Techdegree Student 922 Points

try: count - int(input("Give me a number: ")) except ValueError: print("That's not a number!") else: print("Hi " * count)

Steven Parker
Steven Parker
231,269 Points

As I said in your other question, I suspect you meant to assign the variable count (with "='), not subtract from it (with "-").

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I took the liberty of forking your workspace and taking a look When I do this command python Exceptions.py I get an error saying that count is not defined. . And the reason it's saying that is because you have a typo.

You have typed:

count - int(input("Give me a number: "))

But you meant to type:

count = int(input("Give me a number: "))

Note the equals instead of the minus sign. The minus sign indicates that you are trying to deduct the number input by the user from the current value stored in count. But as this is the first appearance of the count variable, it is currently undefined and has no value. The equals sign, on the other hand, will take the input from the user and try to turn it into an integer. If it succeeds, it will assign the value to count, at which point the count variable will be defined.

Make this tiny change, and your program should run! :sparkles:

Steven Parker
Steven Parker
231,269 Points

Perhaps you're giving the wrong command to start it.

I used:

Python Exceptions.py