Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print twice?????
#1
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!
Reply
#2
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.
Reply
#3
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.
Reply
#4
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
>>>
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020