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!

random numbers

Syntax

print
random
.
randint
(
low
,
high
)

About random numbers

Note – You must import random before using random numbers.

Random numbers are produced in python by using the random module. The video below demonstrates how to use one function from the random module, randint(a,b). Random numbers on a computer are actually the product of a repeatable algorithm  As such they can not produce truly random numbers. However they are random enough for most programs.

The code below is from the video –

import random

dice = random.randint(1,6)

if dice == 1:
	print "you win"
else:
	print "you lost with the roll of ", dice

Key terms

function – A named block of code which can be called to perform another task. They can be pre-written in modules or created by the programmer.

Module – A pre-written selection of related functions collected together for use by other programmers.

Helpful links

Python docs for the random module

Random seeds

More detail on random functions

 

Test your skill

1. Write a program which will display a random number between 20 and 30.

Task 1: Answer SelectShow

2. Write a program which will roll two six-sided die and display their totals.

Task 2: Answer SelectShow

3. Write a program which will allow the user to pick a number between 1 and 1000. The computer will then select a random number between 1 and the number entered.

Task 3: Answer SelectShow

Leave a Reply

You must be logged in to post a comment.