Skip to content

Tag: loops

How to deny letters and symbols in loops

I only want my code to accept numbers between 1 to 9. I tried try except, logical operators, isdigit, but I just can’t do it. Answer It look like you’re trying to print out the prompt based on the user input, and you want to make sure that it’s not higher the 9 and lower than 1. You need to

Change value every nth iteration python

How can I change a value inside a loop every 10th iteration? Say I have a list with 30 properties I would like to change the value of x by a factor of 10 every 10th time. Desired outcome ** Answer Modulo is a nice way of doing that: Edit: you should probably initialize x outside the loop.

Looping through HTML & following links

I am writing a code that is supposed to open a url, identify the 3rd link and repeat this process 3 times (each time with the new url). I wrote a loop (below), but it seems to each time sart over with the original url. Can someone help me fix my code? Answer You need to define the empty list