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 Try and Except

Sabas Mejia
Sabas Mejia
378 Points

BUMER !

What's wrong with code ? : (for I tried all possible codes and still says "Try again!" try: num1 = int(input("Give me the 1st number: ")) num2 = int(input("Give me the 2nd number: ")) float(num1) float(num2) except ValueError: print("None") else: print(num1 + num2)

trial.py
try: 
    num1 = int(input("Give me the 1st number: "))
    num2 = int(input("Give me the 2nd number: "))
    float(num1)
    float(num2)
except ValueError:
    print("None")
else:
    print(num1 + num2)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Many of the challenges moving forward will not utilize the input and print for input and output. Instead the challenge checker will exercise the code by calling the function with various arguments to test the code.

Items to correct in your code:

  • remove input statements
  • change print statements to return statements
  • convert to float using reassignment, such as: num1 = float(num1)
  • returning nothing is the same as return with no argument

Post back if you still have issues. Good Luck!!