Python Forum

Full Version: print twice?????
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def print_twice(bruce):
print ("bruce")
print ("bruce")

print_twice("spam")
bruce
bruce
print_twice(17)
bruce
bruce




The book says if i type in print twice it will print whatever i type TWICE....wtf am doing wrong now. Does anyone know of a real book for idiots like me....This book is missing too much information. It doesnt tell you enough...

If i want to print something twice how can i do that....?
I understood when i wrote the code the crap wasnt going to print "spam" twice because its defined as bruce...so how can i create a function that DOES work like i want it to???

I feel like im reading chinese sometimes trying to learn this stuff, any other books someone with ZERO computer experience can read or watch to learn EVERYTHING???

thank you!
bruce is a python identifier, the name of a variable.
"bruce" is a string.

Looks like you got the two mixed up.
I don't know what book you're using, but I seriously doubt that the mistake is the books fault.

Also, please read the link describing how to post code.
http://www.greenteapress.com/thinkpython...hap03.html sections 3.8-3.9

The link your talking about is the BBcode one?

Im new to this page and i dont use the internet much.
The code in the book you linked is correct, but it is also python2.

If you are using python3 it would look like this:
>>> def print_twice(bruce):
...     print(bruce, bruce)
...
>>> print_twice("spam")
spam spam
>>> print_twice(8887)
8887 8887
>>>