Ask coding questions

← Back to all posts
I am getting an error and I want a fix .-.
MATTHEWBECHTEL (122)

Here is the link - https://repl.it/@MATTHEWBECHTEL/Ffncehjanddfkicysbjizdpch3pco
It says SyntaxError: EOL while scanning string literal
As stated in the screenshot below

Answered by JustARatherRidi (191) [earned 5 cycles]
View Answer
Commentshotnewtop
JustARatherRidi (191)

That's odd, the repl works fine for me. However, from the picture, your ending double quote looks a bit odd. Are you typing on your mobile?

MATTHEWBECHTEL (122)

I fixed before you typed your message if you scroll through the messages but I have a new problem now .-. The repl won’t even run now. @JustARatherRidi

JustARatherRidi (191)

@MATTHEWBECHTEL Did you fix this one as well? because this one seems fine too.

heyitsmarcus (287)

@MATTHEWBECHTEL What I can't fathom is why you would accept the answer that does nothing towards helping you find a solution.

And the way you wrote the functions is a bad programming habit you'll want to get out of right away. Don't overwrite a function over and over again with different behavior to accommodate new functionality; instead, implement different behavior into your original function to accommodate new functionality.

JustARatherRidi (191)

@MATTHEWBECHTEL I agree with @heyitsmarcus here, you definitely should have chosen his answer.

JustARatherRidi (191)

@MATTHEWBECHTEL You're right, but you should try and choose the answer that is more relevant to you and others in the future.

MATTHEWBECHTEL (122)

Isn’t there a song about that or something. @JustARatherRidi

MATTHEWBECHTEL (122)

Also you forgot the period at the end of your sentence. @JustARatherRidi

JustARatherRidi (191)

@MATTHEWBECHTEL Idk, if there is it doesn't seem like my kind of song, not gonna lie. What period?

heyitsmarcus (287)

If you're going to have two different time.sleep() times, you should just pass in the time to the original write function that you need like so:

import sys, time 

def write(string, fltime):
    for char in string:
       sys.stdout.write(char)
       sys.stdout.flush()
       time.sleep(fltime)
write("I am going to count to 1 to 1,000. ", 0.025)
time.sleep(0.75)
write("Follow every word and diget to know if this speed is just right for you. ", 0.025)
time.sleep(0.75)
write("Here we go. ", 0.025)
time.sleep(.5)
write("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, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100. ", 0.015)

Here's a fork of your repl: https://repl.it/@heyitsmarcus/Writing-as-though-typing

If this solves your problem, please upvote and select my answer as the accepted answer to close this question.

MATTHEWBECHTEL (122)

Maybe I’ll that try that thanks. Btw I like knives more than forks. Spoons are good aswell. @heyitsmarcus

heyitsmarcus (287)

@MATTHEWBECHTEL Well, I can tell I wasted my time attempting to help you. Good luck, bud. You're going to need it.

MATTHEWBECHTEL (122)

......... I don’t get what the number at the end of the sentence does. @heyitsmarcus

MATTHEWBECHTEL (122)

They don’t even do anything.... @heyitsmarcus

heyitsmarcus (287)

@MATTHEWBECHTEL If you look at your original write function, there is a second parameter that I named fltime (you could rename this to something else). In the very bottom line of the function, where you have time.sleep(0.03), I changed it to time.sleep(fltime) which will allow the function to use whatever value you pass in.

That means that you can control the time in every single write statement without having to overwrite the write function multiple times. You will only have one write function instead of tons of them, which you should not have...

MATTHEWBECHTEL (122)

Yeah but what does the numbers at the end of every write function mean? @heyitsmarcus

heyitsmarcus (287)

@heyitsmarcus Notice that I passed in the time to sleep at the end of every write call. This means you have more power over the program, it's more efficient, and other people will know what's going on.

MATTHEWBECHTEL (122)

Ok so basically what I notice is going on is that in line 7.... between every write command it waits that amount so I’m very confused why we have the numbers at the end of the write statements separated by commas. I am re-writing the write statement because I want pauses like a human would talk. @heyitsmarcus

heyitsmarcus (287)

@MATTHEWBECHTEL The comma separates parameters given to functions and the parameters themselves. In your first function, you had only one parameter, so there are no commas needed to separate any other parameters.

i.e.

def write(string):
...
#and then in every function call...
#only one parameter, which is string
write("I am bob the robot.")

But, when you add more parameters, you separate them by commas inside the function. The way you are writing it, you have to overwrite the function every single time you want to change the timing. What I showed you is a way to not do that. It's the way that everyone else is going to use because not only is it more efficient but it's more readable.

#two parameters, separate them by commas
def write(string, fltime):
...
#and then in every function call...
#there are two parameters
#first one is the string to use
#second one is the timing to use for this write statement
write("I am bob the robot.", 0.03)

Does that make sense? Also, please upvote these comments because I'm spending a lot of time helping you lol.

MATTHEWBECHTEL (122)

Sure I’ll upvote every comment you use to help me XD. Ok let me say this back to you... do it my way cuz it’s better, more efficient, and better. I’m not disagreeing. and.... the first one is for how much time it waits between characters, and the number at the end of the scent since I’d the time it waits between every time of “write” statements. @heyitsmarcus and you have 74 upvotes now. Good job.

heyitsmarcus (287)

@MATTHEWBECHTEL Matthew, this is not my way. This is the way that programmers do it. I wasn't the inventor of doing things in that way. It's a way that not only makes more sense, but is again, more readable to other programmers who are trying to flipping help you.

You have a poor attitude, Matthew, and again, best of luck bud.

MATTHEWBECHTEL (122)

Yeah, I know that lol. But did I at least understand the code right? @heyitsmarcus

heyitsmarcus (287)

@MATTHEWBECHTEL Okay, I'll try this again, but please refrain from sarcastic comments lol.

Look at the last line of your write function. That number you have in there is a constant. But you can make it into a variable, so that you can pass it in to your write function like I showed you in the forked code. The number that I pass in each time to write takes the place of fltime in the function. Does that make more sense?

MATTHEWBECHTEL (122)

Yes it does, and I actually wasn’t being sarcastic at all before though. @heyitsmarcus

heyitsmarcus (287)

@MATTHEWBECHTEL Now not to confuse you any further, but instead of having to remember those times, you can write in your own constants. Like let's say one time is slower than another, you could store 0.03 as slowType and 0.015 as slowerType. And instead of remembering and passing back those numbers, you just pass back slowType and slowerType like this:

import sys, time 
slowType = float(0.03)
slowerType = float(0.015)
def write(string, fltime):
    for char in string:
       sys.stdout.write(char)
       sys.stdout.flush()
       time.sleep(fltime)
write("I am going to count to 1 to 1,000. ", slowType)
time.sleep(0.75)
write("Follow every word and diget to know if this speed is just right for you. ", slowType)
time.sleep(0.75)
write("Here we go. ", slowType)
time.sleep(.5)
write("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, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100. ", slowerType)
MATTHEWBECHTEL (122)

@heyitsmarcus Ok, I'll try it when I get time. (:

heyitsmarcus (287)

Your repl is running fine. Did you already fix the problem?

MATTHEWBECHTEL (122)

Yeah but there’s a new problem now XD. @heyitsmarcus

MATTHEWBECHTEL (122)

Wait never mind... I fixed it. The error was in line 8 and 10. The last 2 " was “ instead. Sorry.