Difference between revisions of "Making AI with Python"

Line 2: Line 2:
  
 
This manual will only work if you know Python. If you don't, go learn it at: [[Getting Started With Python Programming]].
 
This manual will only work if you know Python. If you don't, go learn it at: [[Getting Started With Python Programming]].
To start off, we might be a little intimidated by the blank code window. However, don't worry, here's something to fill it with:
+
 
  import random
+
 
Yep! Not much, but pretty neccesary.
+
 
 +
Let's start off with a little challange:
 +
 
 +
'''Say 'hi' to the user when they greet the code, and 'bye' when the user says bye to the code.'''
 +
 
 +
 
 +
First, we need to now what the user says. So we can send them a little input box called 'user_says':
 +
 
 +
user_says = input('Hi or Bye?')
 +
 
 +
Great! Now we need to recognise if they are saying 'Hi', or if they are saying 'Bye'.
 +
 
 +
user_says = input('Hi or Bye?')
 +
if user_says == 'Hi':
 +
    pass
 +
elif user_says == 'Bye':
 +
    pass
 +
 
 +
Nothing happens, no matter what you say. Let's fix that:
 +
  if user_says == 'Hi':
 +
    print('Hello!')
 +
elif user_says == 'Bye':
 +
    print('Bye... :(')

Revision as of 22:17, 14 September 2023

Introduction

This manual will only work if you know Python. If you don't, go learn it at: Getting Started With Python Programming.


Let's start off with a little challange:

Say 'hi' to the user when they greet the code, and 'bye' when the user says bye to the code.


First, we need to now what the user says. So we can send them a little input box called 'user_says':

user_says = input('Hi or Bye?')

Great! Now we need to recognise if they are saying 'Hi', or if they are saying 'Bye'.

user_says = input('Hi or Bye?')
if user_says == 'Hi':
    pass
elif user_says == 'Bye':
    pass

Nothing happens, no matter what you say. Let's fix that:

if user_says == 'Hi':
    print('Hello!')
elif user_says == 'Bye':
    print('Bye... :(')