Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 67,986 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!!