joon_bug joon_bug - 2 years ago 73
Python Question

User-Defined Functions and Learning to Think Like a Computer Scientist with Python

I am brand new to coding / programming and am starting with the foundations of Python. I've used a few different resources (Codecademy, Automate the Boring Stuff, and most recently, How to Think Like a Computer Scientist by Using Python).

So far my education has been good, albeit a bit slow to start (not used to thinking in computer terms quite yet!). But I've run into a problem with one of the lessons that I cannot replicate in my IDE. Please see the code below:

def printTwice(bruce):
print('bruce')
print('bruce')


The lesson states the output should be 'Bruce, Bruce' which makes sense logically. However, when I go to run the code I get the following:

===RESTART: /Users/owner/Documents/bruce.py======









So essentially just another line to start a new code from. I am writing this code in a new file and just cannot figure out what I'm doing wrong.

Any help is appreciated.

Thanks!

Answer Source

Add printTwice('bruce') on a new line after the function, with no indentation like so:

def printTwice(bruce):
    print('bruce')
    print('bruce')

printTwice('bruce')

This line will call your printTwice function, passing the value 'bruce' to the variable bruce, which is not used.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download