Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Create and Debug With Thonny

Give Feedback

In order to get a practical idea of how you can use Thonny’s features, you’re going to create and debug a program. You’ll start by importing SimpleCalculator from calculator.simple and then create a new instance of SimpleCalculator.

Then, you’ll introduce a bug to the program. You’ll add a function with a docstring. After you try to call the function, you’ll use the debugger to see what went wrong. You’ll start by opening up the Variables window to see what’s happening as the program runs.

kwf777 on Dec. 2, 2019

I know capitalization is important but I cannot get my code torun after changing it several times:

from calculator.simple import SimpleCalculator

def create_add_string(x,y):
    '''Retruns a string containing an addition expression'''
    return f'{x}+{y}'

my_calculator=SimpleCalculator()
mu_calculator.run(create_add_string(2,2))
print(my_calculator.lcd)

Shell:

 %Debug calculator.py
Traceback (most recent call last):
  File "/Users/kwf777/calculator.py", line 1, in <module>
    from calculator.simple import SimpleCalculator
  File "/Users/kwf777/calculator.py", line 1, in <module>
    from calculator.simple import SimpleCalculator
ModuleNotFoundError: No module named 'calculator.simple'; 'calculator' is not a package
>>>

Darren Jones RP Team on Dec. 3, 2019

Hi kwf777. It looks like you haven’t installed the simplecalculator package. To do this, open Thonny, and go to Tools > Manage Packages, and then search for simplecalculator - the search should come up with a result of simplecalculator by Jacek Artymiak (currently at v0.0.4), and then press Install. If you then close that window and try running your program, it should work now.

kwf777 on Dec. 4, 2019

It was showing as an installed package

Donald Walters on Feb. 27, 2020

I’m certainly missing something conceptually I don’t understand how you can get calculator.simple from installing simplecalculator

from calculator.simple import SimpleCalculator

Ricky White RP Team on Feb. 28, 2020

Hi Donald. That is just the naming convention that the simplecalculator authors chose. So you’re not missing anything conceptually. You’ll find what you need to import in the documentation for any package on pypi (the Python Packaging Repository, where Thorny pulls it’s packages from).

Become a Member to join the conversation.