I get "none" after print(ans)

This is the place for queries that don't fit in any of the other categories.

I get "none" after print(ans)

Postby Donovanx » Sat May 11, 2013 1:29 pm

Code: Select all
#rpg
a = "chad"
b = "dian"
print("Welcome to rpg")
print("please pick a char to play with")
print("1.chad")
print("2.dian")
c = input("")
if c == "1.":
        ans = print("you picked chad to play with!")
elif c == "2.":
        ans = print("you picked diane to play with!")
print(ans)
Hi guys I'm back with another noobish question.
Ifi don't ask others wil so might aswel put it on google.
Anyhow I started to make a simple rpg game with no real idee wat I'm going to do yet or the story line just going at it, I heard its the best way to learn.
So I got input asking wich char you might want to play with and I get evrything as I want it but at the end with print(ans)
I get the proper print output but underneath I get a "none" on a new line.any idee why I get the none?
Last edited by joneshf on Sat May 11, 2013 1:33 pm, edited 1 time in total.
Reason: fixed erroneous code tag
Donovanx
 
Posts: 13
Joined: Fri May 10, 2013 1:54 pm

Re: I get "none" after print(ans)

Postby joneshf » Sat May 11, 2013 1:32 pm

Every function in python has to return something. Even if you create a function without an explicit return statement, it still returns None. Print is a function that returns None. So when you assign the result of a print statement to a variable, you get the value that the statement returns. Which is None. This is why when you print ans, you see None.
joneshf
 
Posts: 8
Joined: Thu Feb 07, 2013 3:48 pm

Re: I get "none" after print(ans)

Postby Donovanx » Sat May 11, 2013 1:57 pm

Ty I'll look into it since your response is stil a litle chiberish to me (should prob start with learning the key words lol)
And ty for fixing the error with the code bar!
And one more thing do you know of any good tuts that's newbi frendly to mabey help me brush up on the basics wich I can read ofline and that's free?srry if its the wrong place for that question
Donovanx
 
Posts: 13
Joined: Fri May 10, 2013 1:54 pm

Re: I get "none" after print(ans)

Postby metulburr » Sun May 12, 2013 1:16 am

And one more thing do you know of any good tuts that's newbi frendly to mabey help me brush up on the basics wich I can read ofline and that's free?


i am not sure what you could find that is free and also offline. A python book would handle offline and easy reading, but yet is not free (well theoretically). There are a ton of website, tutorials, follow alongs online, but then its not offline.

I would say that just slowly plugging along and posting questions here when something gets confusing would be the best method. Of course a book would help, but there are so many books out there now about python that everybody fancies a different one, depending on who you are.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1299
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: I get "none" after print(ans)

Postby setrofim » Sun May 12, 2013 6:13 am

LPTHW or How to Think Like a Computer Scientist. Both are free online (you can buy LPTHW as PDF). You can always save the HTML pages on your computer for offline reading.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests