How can I make a variable dynamically change while on console python3 - python-3.x

I am working on a program and it needs to display the number of seconds that passed since it started. The variable is inside input() like this:
while True:
something = input(str(x) + "seconds have passed. Please input the number in 60 seconds:")
if x == 60:
break
Is there any way to make the x change dynamically while on screen? So it raises every second and also updates on screen without the need to press enter.
If yes, is there also a way to add an if statement that checks when the variable reached 60 and break the loop.

Related

How can i make python return a window that will be soon used to put stuff on? python 3

Currently trying to make a alarm clock, but not sure how to return a seperate window that will soon have numbers on it for the time. Thanks. This is what i currently got right now.
#square interface
#adjustable hour/minute/seconds
#choose stopwatch(stops at a certain time)
#choose timer(counts down from timer)
#a start button
Have not tried anything because i don't know what to type

I am trying to make an image stay put longer after an if statement occurs

I am trying to edit my game so that when an if statement occurs an image appears, but the if statement only happens when the object hits the wall and the ball bounces off, so the image only appears for the amount of time the if statement is active. I tried to make a delay command but after the if statement occurs it freezes the entire game for the given time.
Does anyone know how to isolate a delay command or make the image stay visible for an extra second after the if statement expires/after the ball hits the wall and bounces off???
Here are the lines of code that has to do with this:
image_set = pygame.display.set_mode()
image = pygame.image.load("image.png")
def image():
image_set.blit(image,(600,90))
if object.left == (COLLISION_RANGE) or object.right == (WINDOWWIDTH COLLISION_RANGE):
DisplayOoface()
Oof.play()
Put the code to "hide" the image into a separate function, Use the Threading package to create a new thread and pass that function in to be executed.
Within the function you can add a delay to the start of the code. When you start the additional thread within the if statement, you will have the delay you need, and then the function can hide the image.
If you do not thread this task, then python simply processes one line of code at a time. By passing off the task of waiting and hiding the image to a secondary thread, your main thread (the game) can continue functioning as needed.
https://docs.python.org/3/library/threading.html

Is there anyway to stop implicity wait during try/except?

I have a selenium script that automates signing up on a website. During the process, I have driver.implicity_wait(60) BUT there is a segment of code where I have a try/except statement where it tries to click something but if it can't be found, it continues. The issue is that if the element isn't there to be clicked, it waits 60 seconds before doing the except part of code. Is there anyway I can have it not wait the 60 seconds before doing the except part? Here is my code:
if PROXYSTATUS==False:
driver.find_element_by_css_selector("img[title='中国大陆']").click()
else:
try:
driver.find_element_by_css_selector("img[title='中国大陆']").click()
except:
pass
In other words if a proxy is used, a pop up will occasionally display, but sometimes it won't. That's why I need the try/except.
You can use set_page_load_timeout to change the default timeout to a lower value that suits you.
You will still need to wait for some amount of time, otherwise you might simply never click on the element you are looking for, because your script will be faster than the page load.
In the try block u can lower the timeout say 10 by using driver.implicity_wait(10) or even to 0. Place this before the find element statement in the try block. Add a finally block and set this back to 60 driver.implicity_wait(60).

Python IDLE won't run the code

The code I had wasn't executing whatsoever. So, I tried it with a basic code:
x=10, if x==10:, print ("Hello"),
This worked. But the moment I extended it to anything else, it wouldn't run eg.:
count=0, x=10, if x==10:, count=count+1, if count == 10:, print ("Hello"),
(That had correct indents and exc. the commas.) The loop wouldn't loop.
Anyone understand why? The other queries similar to this regard a different issue. It won't run through CMDLine either. I did uninstall and reinstall it but that changed nothing.
The reason your loop won't run is because there isn't a loop. I think what you're trying to do is this.
for i in range(11):
if i == 10:
print('Hello')
With the current string of commands that you're running, count is simply being increment from 0 to 1, and since count != 10 at that point, you never see Hello.

Print duration of every step in terminal, during watir-cucumber execution

Is there a standard way of printing the duration of every step in the terminal, during a watir-cucumber execution?
It might be possible to make some kind of invention, using the "after step" and a global variable. But, there is a proper way?
You can use hooks like this:
Before do
#last_time = Time.new
end
AfterStep do
now = Time.new
puts "Step duration: #{((now - #last_time)*100).round} ms" # if (now-#last_time) > 10
#last_time = now
end
This is more verbose by outputting the duration on a new line, but unless you want to get more in-depth (by creating your own formatter), you cannot output stuff where you indicated it.
Uncomment the if if you are only interested in steps that take longer than a certain threshold.
The simplest way to do this would be using Ruby's built in Time class. Using Time.new we can record the current time into a local variable before and after the code within the step definition is executed. Then we work out the duration by subtracting start_time from end_time.
#get the start time
start_time = Time.new
#do whatever the step needs to do here
#get the end time
end_time = Time. new
#calculate duration
duration = end_time - start_time
puts duration

Resources