This question already has answers here:
Tell Ruby Program to Wait some amount of time
(7 answers)
Closed 9 years ago.
I am trying to write program in ruby which needs to make a pause before returning text.
In python you can do this by importing time and then using time.sleep(x). How would one go about doing this in ruby.
Ex. in Python
print ("you say hello")
time.sleep(5)
print ("I say goodbye")
For your example, just use
sleep(5)
Related
This question already has answers here:
print variable and a string in python
(6 answers)
Closed 10 months ago.
First I assigned a variable
character_name = "Patrice"
On the print function, I wrote
print( " Patrice does a wonderful job at his workplace ")
Instead of writing Patrice on the print function, I wanted to declare the variable that would print Patrice, How would I do it?
There's various ways to achive this, you might want to look at Pythons f-strings:
print(f'{character_name} does a wonderful job at his workplace')
This question already has answers here:
Can't send input to running program in Sublime Text
(5 answers)
Closed 2 years ago.
I have python 3.7 installed and I have this code:
print("Enter your name:")
x = input()
print("Hello, " + x)
I was writing the name and press enter but the input is not over, it is still running and waiting for more inputs
Edit: the problem is that input is never ending, doesn't matter how many enters I press
Sublime text doesn't support inputting data. Read this : Sublime text input not working
That said, apparently SublimeREPL provides this sort of functionality, although I don’t use it myself so I don’t know much about it.
This question already has answers here:
How do I check whether a file exists without exceptions?
(40 answers)
Closed 4 years ago.
I want to search a CSV-File with python2 on the Raspberrry Pi. If the file is not found the program should generate it. How I can search a file and can decide with an if-statment if there is CSV-file or not?
as #John Anderson said you can use the os module's os.path.
if os.path.exists('path/to/your/csvfile/') is True:
print("Do something")
This question already has answers here:
Command prompt can't write letter by letter? [duplicate]
(3 answers)
Closed 6 years ago.
import random
import time
myStr="1234567890qwertyuiopasdfghjklzxcvbnm.,*/-+>£#$½{[]}\|!'^+%&/()=?_é><`;:"
def generator():
while True:
randomLetter=random.choice(myStr)
print(randomLetter,end="")
time.sleep(0.1)
generator()
I want to slow down my while loop . If i write time.sleep it doesnt output anything .If i delete end="" part it works but i still want to write everything in one line and I also tried with "sys.stdout.write" but it didnt work again.
do sys.stdout.flush() after print
This question already has answers here:
Python indentation mystery
(3 answers)
Closed 6 years ago.
I am a code beginner.Can anyone tell me what happend if I get a syntaxerror when putting the "print" outside the loop
Seems like you are using an interactive interpreter shell. You should hit enter after the last line of the loop before you try to print.
In future questions please write your code in the question body instead of attaching a screenshot.