0

I'm on GrokLearning and am having trouble with this problem:

In rally driving, it's important to know what terrain is coming up on the route. The navigator reads out pacenotes, written in shorthand, so the driver knows what to expect. We've developed a simplified pacenote system for our robotic navigator for a slot car set, using the following shorthand:

r – right

l – left

j – jump

s – straight

Write a program that reads in the terrain, and prints out the course notes. For example:

Terrain: rrsj

right

right

straight

jump
​

If the pacenotes include an unknown shorthand, our robot navigator should panic and print out: Aaaaah!

Terrain: jrdssjkl

jump

right

Aaaaah!

straight

straight

jump

Aaaaah!

left

I'm actually not sure what to do so I haven't tried anything yet... except for:

a = input("Terrain: ")

b = list(a)

Can I have some help please? This is my first post by the way... ​

Bando
  • 1,223
  • 1
  • 12
  • 31
DasGuyDatSucks
  • 103
  • 1
  • 11

1 Answers1

0
# store the rule in a dict.
xdict = {'r' : 'right', 'l' : 'left', 'j' :'jump', 's':'straight'}
# input has type str, which can be iterated to check each char
string = input("Terrain: ")
for x in string:
    # check if the char exists in the dict.
    if x in xdict:
        print(xdict[x])
    else:
        print('Aaaaah!')
ComplicatedPhenomenon
  • 4,055
  • 2
  • 18
  • 45