The Noobs of Python: Ep.1.0 - The Introduction

Welcome to 'The Noobs of Python Ep.1' this thread will feature some easy Python 3.x code for noobs interested in taking the next steps after the traditional print('Hello World') that is the beginning of every programmers adventure.

What will we cover? Simple code and some Regex to test the boundary of what we know. I learn more when challenged and hopefully some of you do as well. Post your questions or code snippets and lets learn together as a community !

So lets get our environments ready and get to coding !

Q: What do I need to get started?
A: A willingness to learn and contribute, including Python package 3x, a Text editor or Notebook [ Idle, Jupyter, Atom, Sublime Text 3, vim, emacs, vscode, nano or what ever you use to write code]
NO TEXT EDITOR/NOTEBOOK HOLY WARS lets be cordial to each other.
A linter for your editor is helpful [ sublimelinter, pylinter, flake8 etc ]

Q: Why do I need a linter?
A: They are helpful with syntax, stylistic errors and some even have explanations of modules, functions and packages.

Q: I am a total noob, can some one hold my hand through some of the examples?
A: That's what we are here for, hopefully you will be up to speed soon enough and your posts can serve as references for newcomers as well. Rarely we will provide the famous 'Google It' answers you see across the web. We are here to learn together, and hopefully the admins will allow us to partake in some healthy discussions about taking our first steps in Code !

Q: I want to be in the fast lane, Machine Learning, Forensic Python and Data Analysis, Where do I go?
A: Hopefully when we get this going, we will start 'The Knights of Python Group' where intermediate and pro's share projects and code, but lets learn to walk first !

Q: You are busy most of the time, where/what do we do if you are not here to start related threads or help with code?
A: I am starting the conversation, the group per-say, is not limited to me and anyone 'respectfully' can contribute, start threads and help. I spend a good chunk of time here doing various things, so I am typically around to help.

Q: I'm on Windows, you guys are on Linux What do I do?
A: Python is not OS specific, Some of our ideology might surround Linux, but is not limited to it. We have to be pragmatic about it.

Q: I have a question,
A: You'll get answers so lets code !


I will post a comment or 2 with some code, hope you all contribute critique and participate positively any way you can.

Welcome to 'The Noobs of Python' !!!

25 Likes

Introductary code and what we learn:

Assuming that everyone here has ran the famous print('Hello World') let's get to some introductory code! Fire up your editor and save the file as Intro.py continue to paste/modify the following:

import time

print('Hello!')
time.sleep(3)
print('What is your name?')
time.sleep(3)
My_Name = input()
time.sleep(3)
print('Welcome to The Noobs of Python Ep.1, ' + My_Name, 'it\'s nice to meet you !')

A couple of things that we do here :
1. import the time module and call sleep() to cause the program to pause for 3 seconds.
2. print() a hello message to the screen.
3. assign the My_Name variable to input() to wait to the user to enter data.
4. print() actually contains the expression 'Welcome to The Noobs of Python Ep.1, ' + My_Name between the parentheses. This adds the expression with the input() and prints to the screen.
5. the backslash in 'it\'s : The backslash (\) character is used to escape characters that otherwise have a special meaning

This is very simple to put together and also allowed us to get input from the user, use a variable, use time and print to the screen.

The next code snippets will be about List, Dictionaries... Post your examples, variations and questions below. Code on Code_Warriors !

9 Likes

Here is my version:

import time

print('Hello!')
time.sleep(1)
print('What is your name?')
time.sleep(1)
My_Name = input()
time.sleep(1)
print('Welcome to The Noobs of Python Ep.1, ' + My_Name, 'it\'s nice to meet you !')
print('Are you coming back to this thread?')
time.sleep(1)
Answer = input()
while Answer[0] != 'y' or Answer[0] != 'Y':
    if Answer[0] == 'y' or Answer[0] == 'Y':
        print("Good...")
        break
    else:
        print("The only acceptable answer is 'Yes'.")
        Answer = input()
2 Likes

I hope this is helpful, I tried to make it a little different so people can see another way to do it. Also maybe this will make me less rusty.

#!/usr/bin/env python3

# Always comment your code!

# import just the sleep function
from time import sleep

# say hi and sleep for 3
print("Hello!")
sleep(3)

# take input after the quoted text and sleep for 3
my_name = input("Enter your name: ")
sleep(3)

# get its name and sleep for 3
its_name = input("What's my name? ")
sleep(3)

# use the format() to place the names at the subtitution markers {}
print("Welcome to The Noobs of Python Ep.1, {} it's nice to meet you! I'm {}.".format(my_name, its_name))
print("I'm super slow :'( fix meeee {} you're my only hope!".format(my_name))
5 Likes

@FriendlyStormtrooper Great Stuff !!! glad you added a while / if in there . Cool

@Eden Fantastic ! I'm glad you did it differently, it's a good perspective and variety for the post.

1 Like

print("""New user here! Hello!
I'm starting a club of sorts for kids about to choose their GCSEs to start learning python in this week, and I thought this whole "Hello, what's your name?" business would be a really neat idea for an introduction! 
Can I borrow this idea? heh!
""")

getAnswer = lambda a=[""]: [a.__setitem__(0, input("Y/N: ").upper()) or (a[0] in ["Y", "N"] or (print("That answer was invalid!") or getAnswer())), a[0]][1]
answer = getAnswer()

{"Y":lambda: print("Thank you!"),
 "N":lambda: print("Oh, okay ._.")}.get(answer)()

If you hit the max recursion depth you deserved it!

1 Like

I have copied the text in the grey box into atom and saved the file as intro.py
When i open it up in python (v3.5.2) I get to what is your name in which I type my name and than python closes. Is there a particular reason for this?

Are you on Windows, MacOS, Linux?

windows 10.

Would you mind posting your code? Or you could run it through a Linter is you have Flake8 or any other.

When I copy/pasted I got an error

Hello!
What is your name?
dude
Traceback (most recent call last):
File "intro.py", line 7, in
My_Name = input()
File "", line 1, in
NameError: name 'dude' is not defined

I changed it to this to get it to run

import time

print('Hello!')
time.sleep(3)
name = raw_input("What is your name?")
time.sleep(3)
print('Welcome to The Noobs of Python Ep.1, ' + name, 'it\'s nice to meet you !')

Can anyone tell me what the difference is? I have just started some tutorial programs and I'm doing stuff but don't really understand what I'm doing if that makes sense. Thanks!

Oh, and love this thread, thanks for creating!

2 Likes

raw_input() is a function used in Python 2.7.x, what we are using is Python 3.x, 2.7 will be the last version of the older Python code. So maybe you can learn some 3.x ! It's not much more difficult :)

1 Like

Ah! Guess I was already working through old tutorials. Glad this was pointed out to me before I got too far into it! Thanks!

1 Like

No problem. Any other questions just ask ! I will be converting some old code into 3.x through these tutorials so hang around !

I tried a couple different ways and I ended putting
time.sleep(#) at the end and than the application didn't shut down until # of seconds. Thanks for the reply! Ill keep tinkering around to see what else I can do.

1 Like

Good to hear you figured it out. If you have doubts, just post your code so we can have a look as well.

sounds good. thanks again for doing this

1 Like

It's because it's run out of things to do so it terminates!
If you want to make it stay open for a while (until someone hits enter, per se) you can just put

input("Press enter to exit.")

at the end! :)

3 Likes

You should use the tags feature and add "Python" to the tags of this category! ;)

1 Like

Wait till my Rust tutorials start coming out. Thanks for your code snippet by the way. Using the lambda function was a good change of pace

2 Likes