0

I want to make my raspberry pi ask me a question, but not with sound, with text. I learned how to do it a while ago, but I forgot.

1
  • 1
    How to put this. Mmmh. This question really is too non-specific to get many helpful answers. What is it you want to do? Do you want to write a program to fulfil that task? If so what programming/scripting language do you know or want to use? Or do you want to install a ready program to do your bidding? If so what operating system do you run on your RPi?
    – Ghanima
    Sep 6 '14 at 14:50
1

Like @Ghanima said in the comments, this question is a bit too non-specific and I'm not sure exactly what you want. However, I think I can provide a basic answer.


Python is the language of choice for the Raspberry Pi (the Pi in the name is a take on Python) and comes pre-installed on Raspbian, so the example I'll provide will be in Python.

This will be a very basic Q/A Python script. If you want more in depth features and more control, I suggest checking out Learn Python.org, Learn Python the Hard Way, or Codecademy's Python Course.

Teh Codez

A basic Q/A script written in Python 3.3, you can run it via python3 [YOURFILENAMEHERE].py

print("Hey there!")
going = input("How's it going? ")
print ("Oh that's great! It's going",going,"for me too")
age = input("How old are you? ")
print ("Really?",age,"is a great age!")
print ("Okay, bye for now!")

Explanation:

You'll notice print comes up a lot in this script, it starts 4 of the 6 lines. That's the statement, or keyword, for print ing something to the screen. You'll also notice that whatever's within the area between the Parenthesis is printed.

However, in the case of print ("Oh that's great! It's going",going,"for me too") and print ("Really?",age,"is a great age!"), you'll notice the quotation marks end, and are followed by a comma, then a variable (going or age respectively.) Like this: going",going,"for.

This is one way, in Python, you can print data that a variable is holding. The commas insert a space while the variable tells what to print.

And that brings me to the next point, variables. In the going = input("How's it going? ") and age = input("How old are you? ") lines, you'll notice a word, then an equals sign (=), then input.

The first word (going or age respectively) is the variable that the input statement will put its input in. In simpler terms, the first word stores what you give the computer when it asks. If you enter good! for the first question, the computer will store good! in the going variable.


That's all I'm going to share, I don't want to give a full lesson on Python code within the bounds of a Stack Exchange answer. Again, if you want to learn more about Python, follow those links I gave above.

Hope this helped!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.