Изучение Python (while loop project)
Здравствуйте, я учусь в своем самом первом классе программирования, чтобы стать инженером-программистом. Мой вопрос касается вопроса о цикле while. Ниже приведен мой код:
For this challenge you must write a function named count_to_n . This function should take one argument (you can safely assume that all arguments will always be positive integers), and it should print all integer values from 1 to the argument value - one number on each line. This function must use a while loop to count from 1 to the value of the argument. So the n for this project can either be 2, 3, 5, or 10. I did a code that goes to n 10 but I was wondering how I can modify it for it to be any number and still get it right. For example if I put n as 20 the code will not work or if its 55. Sorry I'm a beginner and I'm just trying to figure out things on my own since is an online class.
Что я уже пробовал:
def count_to_n(n): if n == 2: n = 1 while n <= 2: print(n) n = n + 1 elif n == 3: n = 1 while n <= 3: print(n) n = n + 1 elif n == 5: n = 1 while n <= 5: print(n) n = n + 1 elif n == 10: n = 1 while n <= 10: print(n) n = n + 1 else: return