Hej allihopa.
Av ren nyfíkenhet undrar jag om någon mer än jag programmerar i Python. Det finns flera versioner av Python men jag programmerar mest i iPython Notebook - Python 3.0. Om ni inte redan programmerar föreslår jag att ni börjar då det är väldigt roligt. Vill ni öppna konsolen där du skriver kod kan du antingen öppna cmd och skriva "python qtconsole" eller "ipython notebook".
Jag har ett program, en liten version av Siri som jag har börjat på, det vore roligt att se vad ni kan göra med den, här är koden;
====================================================================================================================
def launch():
global name
print "Hello"
name = raw_input("\n> What's your name?;\n\n")
# Setup 1
# IMPORT 1
import time
import datetime
# Other
def time_check():
t = datetime.datetime.now()
h = t.hour
m = t.minute
if h > 21 and m > 0:
print "Go to sleep. It's not healthy to be up all night"
night = True
else:
night = False
return night
# DEFINE 1
def moon_cheese():
t = datetime.datetime.now()
h = t.hour
m = t.minute
if h > 19 and m > 0:
night = True
else:
night = False
print "It's just the way it works", name, "."
if night:
print "\n> It's late, you should be able to see the moon if you look out the window."
def bamse_who():
print "http://www.bamse.se/"
def t_basic():
n = datetime.datetime.now()
print "Local time is", n.hour, ":", n.minute, "."
def question(q):
answer = raw_input(q)
if answer.upper() in [x.upper() for x in ["What's the time?", "What is the time?", "What time is it?",
"What's the time", "What is the time", "What time is it"]:
t_basic()
time_check()
question("\n> New input;\n\n")
elif answer.upper() in [x.upper() for x in ["How do I become Bamse?", "How do I become Bamse"]:
bamse()
time_check()
question("\n> New input;\n\n")
elif answer.upper() in [x.upper() for x in ["Who is Bamse?", "Who is Bamse", "Who's Bamse", "Who's Bamse?"]:
bamse_who()
time_check()
question("\n> New input;\n\n")
elif answer.upper() in [x.upper() for x in ["Why is the moon a cheese", "Why is the moon a cheese?"]]:
moon_cheese()
time_check()
question("\n> New input;\n\n")
elif answer.upper() in [x.upper() for x in ["Can I change my name", "Can I change my name?"]:
name = raw_input("\n> Enter a new name;\n\n")
if name in ["emil", "Emil"]:
print "\nGood choice! Best name I've ever heard", name, "."
question("> ☆ Again, good choice. New input;")
else:
print "\nNice, name un-succesfully changed to", name, "."
question("\n> New input;\n\n")
def bamse():
print "\n> You dont,", name, "."
def w_do():
print "\n\n> Things you can ask me:\n"
print " ● What's the time?"
print " ● How do I become Bamse?"
print " ● Who is Bamse?"
print " ● Why is the moon a cheese?"
print " ● Can I change my name?"
print " ● Is god an atheist?"
print "\n> More features will be added soon."
# Launch 1
print "\n> Hello there,", name, "."
t_basic()
w_do()
question("\n> Prompt\n\n")
====================================================================================================================
Testa att skriva "ipython notebook" i cmd, datorn kommer öppna antingen Internet Explorer, Chrome eller Firefox beroende på vad du har för standard-webbläsare. Klicka på "New" och välja Python 2 ( se första bilden ) , klistra in koden, sen tryck på shift och return samtidigt. Skriv sedan "launch()" ( se andra bilden ) och tryck ned shift och return igen. testa ändra i koden och se vad ni kan göra för att förbättra den!
mvh
troffaholic