Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Brand new to programming
#1
I am a newbie and have a question. I am following a guide and typed a few line and ran with Python 3.7 on a Mac. When I run it some of the output prints the parenthesis. What and I doing wrong?
Here's the code:
print("I will now count my chickens:")
print("Hens", 25 + 30 / 6)
print("Roosters", 100 - 25 * 3 % 4)

print("Now I will count the eggs:")

print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6) 
print("Is it true that 3 + 2 < 5 - 7?")
print(3+2<5-7)
print("What is 3 + 2?", 3+2)
print("What is 5 - 7?",5-7)
print("Oh, that's why its False.")
print("How about some more.")
print("Is it greater?" ,5>-2)
print("Is is greater or equal?", 5>=-2)
print("Is it less or equal?",5<=-2)
Hers the run:
I will now count my chickens:
('Hens', 30)
('Roosters', 97)
Now I will count the eggs:
7
Is it true that 3 + 2 < 5 - 7?
False
('What is 3 + 2?', 5)
('What is 5 - 7?', -2)
Oh, that's why its False.
How about some more.
('Is it greater?', True)
('Is is greater or equal?', True)
('Is it less or equal?', False)


I'm sure it's something stupid. Thank you in advance. Also if this is the wrong place to post please point me in the right direction.
Reply
#2
Are you sure you ran it in version 3.7? That's the behavior you would expect running it in 2.7 or earlier. Then print was a statement like return, and didn't need parentheses. So putting the parentheses makes it think you want to print a tuple.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
I figured it out, The lines should be print("Hens"),25+30/6. The parenthesis should be after the text and before the match operation. Thank you.
Reply
#4
No, you're running it in 2.7. That's the problem. You've just changed the syntax into what 2.7 expects. That may work, but if you're new to Python, you want to learn with 3.7.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
Use Python3, don't learn 2.
With print statements, is it true you can not combine different types with a operator concatenation? You can only print out with a comma?
For example:
print('He', 110, ' World')
will work,
but,
print('He' + 110 + ' World)
will not.
I could try this out myself but I ran into an error this week with this and thought I'd throw it out there.

Actually, just cause now I'm curious, that is the correct result.
 print('He' + 110 + 'World)
  File "<stdin>", line 1
    print('He' + 110 + 'World)
    SyntaxError: EOL while scanning string literal
versus:
print('He',110, 'World')
He 110 World
Phil
Reply
#6
Thank you all. I have download the correct version ( 3.7 ) and it works.
Reply


Forum Jump:

User Panel Messages

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