473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

new to python, like really new.

hi, I just started python, I'm 14 years old and new experience in any programming whatsoever. I recently got a new machine and I want to make use of it. so instead of gaming like I have done in the past,I decided I'll start doing some programming. I am currently running Linux Mint 12. I have python 2.7.

now here is the syntax problem. I'll show you it. of course this isn't the exact thing, Because I made it simpler.

a = 1 + 1
b = 2 + 2
c = a + b

print C

here's the problem.

>>>if 6:
... print "value of C is:"

now something isn't right there. now you see that I'm trying to print the value of it if its right but I don't know how.

if you can help, that would be great.


By the way, if anyone here who is a professional programmer and wouldn't mind helping me with a few other things, please email me @ xx@xxx

Thanks.
Feb 9 '12 #1
3 1642
bvdet
2,851 Expert Mod 2GB
I removed your email address for your protection. Since you are a member, you can private message other people. Feel free to ask any questions you may have about programming! We will try to help in any way possible.

I am not a professional programmer. I do structural steel detailing and write Python scripts to facilitate my work in the 3D model.

The statement if 6: will always evaluate True just like if 0: will always evaluate False. You will want to learn how to format strings for printing to stdout.
Expand|Select|Wrap|Line Numbers
  1. >>> a = 1 + 1
  2. >>> b = 2 + 2
  3. >>> c = a + b
  4. >>> if c == 6:
  5. ...     print "value of C is: %s" % (c)
  6. ...     
  7. value of C is: 6
  8. >>>
BV - Moderator
Feb 9 '12 #2
bvdet,

thanks for editing it. I'm sorry I failed to follow that rule (just read it now)

as for that code you gave me, are you sure that is the only way of doing it? (with the %?) what is % even used for?

thanks,
mendy.
Feb 9 '12 #3
bvdet
2,851 Expert Mod 2GB
There is a pretty good explanation of the string format operator "%" at http://infohost.nmt.edu/tcc/help/pubs/lang/pytut/str-format.html.

You can print the result by issuing multiple print statements or string concatenation, but generally those methods are slower.

Expand|Select|Wrap|Line Numbers
  1. print "value of C is: " + str(c)
  2.  
  3. print "value of C is:",
  4. print c
It's generally a good idea to issue only one print statement where possible. Use string method join() to create a long string from string fragments instead of concatenation.
Expand|Select|Wrap|Line Numbers
  1. >>> stringlist = ["Sentence 1", "Sentence 2"]
  2. >>> print "\n".join(stringlist)
  3. Sentence 1
  4. Sentence 2
  5. >>> 
String formatting is very important. The best time to learn how to use it is now!
Feb 9 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Tolga | last post by:
After a very rapid entrance into the Python, I have immediately looked for a good IDE. Komodo and Wing IDE look very good and I think they are enough. But now, I am searching for a Pyhton...
28
by: john_sips_tea | last post by:
Just tried Ruby over the past two days. I won't bore you with the reasons I didn't like it, however one thing really struck me about it that I think we (the Python community) can learn from. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.