/
hello.py
35 lines (29 loc) · 1.09 KB
/
hello.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from itertools import chain
class SolarSystem:
planets = [list (chain (planet, (index + 1,))) for index, planet in enumerate ((
('Mercury', 'hot', 2240),
('Venus', 'sulphurous', 6052),
('Earth', 'fertile', 6378),
('Mars', 'reddish', 3397),
('Jupiter', 'stormy', 71492),
('Saturn', 'ringed', 60268),
('Uranus', 'cold', 25559),
('Neptune', 'very cold', 24766)
))]
lines = (
'{} is a {} planet',
'The radius of {} is {} km',
'{} is planet nr. {} counting from the sun'
)
def __init__ (self):
self.lineIndex = 0
def greet (self):
self.planet = self.planets [int (Math.random () * len (self.planets))]
document.getElementById ('greet') .innerHTML = 'Hello {}'.format (self.planet [0])
self.explain ()
def explain (self):
document.getElementById ('explain').innerHTML = (
self.lines [self.lineIndex] .format (self.planet [0], self.planet [self.lineIndex + 1])
)
self.lineIndex = (self.lineIndex + 1) % 3
solarSystem = SolarSystem ()