MrRussells
Posts: 2
Joined: Sat Apr 19, 2014 1:18 pm
Location: Essex

basic code for a noob

Mon Apr 21, 2014 1:08 pm

Hi,

I have recently purchased a Raspberry Pi with the aim to learn some programming.

I have previously completed the "Hello World" tutorial and thought i could progress on unfortunately I don't have any knowledge with this to i am reaching out for some help.

Currently I have:

Print ("Hello what's your name")
name = input ("name: ")

I then want to print code to pull through.

Print ("Hello its nice to meet you <name>") but i don't know the code to pull the name previously added to show here.


any ideas?

Russ

pangren
Posts: 42
Joined: Thu Dec 19, 2013 2:52 pm

Re: basic code for a noob

Mon Apr 21, 2014 3:01 pm

You're using Python 3?

Try this :

Code: Select all

Print ("Hello what's your name")
name = input ("name: ")

Print ("Hello its nice to meet you " + str(name))
it should work, but not the most elegant.

Sue B
Posts: 15
Joined: Thu Feb 27, 2014 7:55 pm
Location: Somerset

Re: basic code for a noob

Mon Apr 21, 2014 3:18 pm

"Hello World" is a great start, but you will need to follow some more tutorials if you are going to progress. The syntax of any programming language has to be exact to work, and you will be very slow if you try to do it by trial and error. I suggest you Google <Python Tutorial>, or search YouTube, or buy a basic book. I used all three to start me off, but I have programmed before (albeit 40 years ago).
Select the one you feel most comfortable with - just be sure that it is Python3. (I got very confused when I first started as I ended up with a mix of the two versions which will never work).

Hope this helps,
Sue B
Raspberry Pi Noobie!

User avatar
rpdom
Posts: 14744
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: basic code for a noob

Mon Apr 21, 2014 3:54 pm

There are a lot of good Pi-based tutorials in the MagPi online magazine (free download) at http://www.themagpi.com/

User avatar
paddyg
Posts: 2330
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: basic code for a noob

Mon Apr 21, 2014 7:16 pm

good luck with learning python (and coding generally). On your specific question:
the old system (which python still supports) was based on the C style printf system where you could put %s type placeholders in a string and then follow it with the variable(s) you wanted to insert so in your case

Code: Select all

print ('Hello its nice to meet you %s' % name)
Lots of people still use this method but the 'modern' way of doing this is using curly brackets and as this style is now pretty widely adopted you are best to go with that IMHO!

Code: Select all

print ('Hello its nice to meet you {}'.format(name))
https://docs.python.org/2/library/strin ... formatspec
PS by widely adopted I mean in the wider world of web programming search for liquid templates as used in things like jekyll, django, flask, rails etc
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
tewe
Posts: 37
Joined: Tue Apr 22, 2014 2:49 pm

Re: basic code for a noob

Wed Apr 23, 2014 5:04 am

You can download Minecraft Pi Edition and hack it using Python. That is a fun way of learning Python.
If you don´t know how to start with Minecraft Pi Edition just search for "hacking minecraft pi edition" and a result uploaded by Tinkernut will show up. That video is a good tutorial.

Good luck!
I'm a swedish viking with big beard, I like to eat raspberry pi.

Return to “Python”