Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sequence subtraction
#1
Hello! I am making a game where you enter a path for a drone to fly in, and you must enter the movements right. In the case below, the correct way to get through would be the sequence sddddwx. However, the player can get a 'free-bee', and have any number of characters wrong, and still pass. The errors that will pass unnoticed will be defined using the variable error. How would I make a program that would not notice a number of wrong characters? Thank you.
The error is defined:

print"Newest upgrade purchased!"
error = error + 1
money = money - 1000000
print"You can make",error," mistakes."
The maze:

    print("""

|A----B|    From A drop Paratrooper 4 (v) at B
|______|        Time limit: None.""")
r1 = raw_input("Commands:")
Reply
#2
1. Next time. Show the work. That you want help on.

It pretty simple.
Just loop over word.
Compare against correct word code.

Try it yourself then look at code.
99 percent of computer problems exists between chair and keyboard.
Reply
#3
What do you mean by

Quote:Just loop over word.
Reply
#4
Loop over the word.
Then you compare it to your correct output.

for loop.
word = 'sdddwx'
for letter in word:
    print(letter)
for range loop
word = 'sdddwx'
for i in range(len(word)):
    print(word[i])
while loop
word = 'sdddwx'
length = len(word)
i = 0
while i < length:
    print(word[i])
    i += 1
99 percent of computer problems exists between chair and keyboard.
Reply
#5
How do I compare it against the correct word code?
Reply
#6
1. Seems like you need to go through the beginner tutorials. Before making a game.
basic programming.
a. variables (integer, float, strings, etc)
b. logic and logic operators (if .. elif .. else) (==, !=. etc)
c. loops (for, while)
d. functions (def)
e. containers (tuple, list, dict, class)
f. keywords

If logic.
code = 'sddddwx'
word = 'sdddwwx'
if word[0] == code[0]:
    print(True)
example. Try mixing logic with a loop. Before looking at code.
99 percent of computer problems exists between chair and keyboard.
Reply
#7
Now, how do I get rid of errors if the string is only one letter, while using the code below:
code = raw_input("Code:")
errors = 0
word = 'sdddwwx'
if word[0] == code[0]:
    print("Good!")
else:
    errors = errors + 1

if word[1] == code[1]:
    print("Good!")
else:
    errors = errors + 1
Reply
#8
Take a look at the Hide/Show in Windspar's last post.
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply
#9
To solve your problem. A few keywords and a loop with logic.

keyword min
print(min(5, 3))
keyword range.
print(list(range(10))
for i in range(10):
    print(i)
keyword len
word = 'sddwx'
print(len(word))
play with code.
try to solve it yourself.
then look at code in above post.
99 percent of computer problems exists between chair and keyboard.
Reply
#10
So, this is the final code:

errorlevel = 0
errors = 0
r1 = raw_input("Commands:")
word = 'sdddwwx'
for i in range(min(len(r1), len(word))):
    if r1[i] != word[i]:
        errors += 1
if errorlevel >= errors or errors == 0:
    print"Good!"
else:
    print errors
Thank you for your help.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020