Latest Awards
Complete 10 python programs which focus on loops.

morgan

Score over 100 points in total

vincebanter10

Complete any 5 python programs

vincebanter10

Complete 3 python list based tasks

vincebanter10

Complete 5 python list based tasks

vincebanter10

Complete 10 python list based tasks

dman12

Score over 1000 points in total

april-logan

Complete any pygame task

april-logan

Complete any 3 pygame tasks

april-logan

You have to complete 5 pygame tasks

april-logan

Score over 500 points in total

sam-edmund

Complete any pygame task

sam-edmund

Complete any 3 pygame tasks

sam-edmund

You have to complete 5 pygame tasks

sam-edmund

Complete any pygame task

12wrigleyf

Complete any 3 pygame tasks

12wrigleyf

You have to complete 5 pygame tasks

12wrigleyf

Score over 500 points in total

jhoughton12

Complete any 10 python prograns

jhoughton12

Complete 10 python programs which focus on loops.

jhoughton12

Python Score
tasks = 0
achivements = 0
freestyle = 0
Total = 0
Top 5 Scores
114gilo 3500
2joss-nolan-2 2530
3alexdawkins 2515
4byrnebrian 2080
512wattsl 1750
Click to view all scores
Who else completed this task?
No one has completed this task yet. Be the first!

raw_input

Syntax

result
=
raw_input
(
'question?'
)

About raw_input

raw_input allows you to get text from the user for later use in your program. In order to use raw_input you need to combine it with variables.

 

 

The sample code is taken from the video. Try and add a few more questions and a few more calculations to ensure you understand it.

 

name = raw_input("What is your name?")
hobby = raw_input("What is your hobby?")
age = int( raw_input("how old are you?") )
print "hello", name
print "you like", hobby
print "your age is", age
print "your age doubled is", age * 2

Note – If you need a number then you must use int() as shown on line 3.

Key term

Casting – the process of converting a variable from one data type to another based on the casting rules of the language.

Helpful links

http://python4kids.wordpress.com/2010/07/01/interacting-with-raw_input/

http://en.wikibooks.org/wiki/Non-Programmer’s_Tutorial_for_Python_2.6/Who_Goes_There%3F

http://www.wellho.net/resources/ex.php4?item=y102/yraw – NOTE this link shows the difference between input and raw_input

http://learnpythonthehardway.org/book/ex14.html

Test your skill

1. Create a program which will calculate the area of a circle using the formula 2 * PI * R. The partial code is shown below. To get this to work you must cast the text to a string!

radius = ???????????
PI = 3.14
print "the area is", 2 * PI * radius
Task 1: Answer SelectShow

2. Write a short program which will take any question entered by the user and will then print “do you know” in front of it.

Task 2: Answer SelectShow

Leave a Reply

You must be logged in to post a comment.