Skip to content
Advertisement

Tag: loops

Calculating min, max without using a list

I am trying to solve a problem from a python textbook: Write a program that asks the user to enter the number of times that they have run around a racetrack, and then uses a loop to prompt them to enter the lap time for each of their laps. When the loop finishes, the program should display the time of

For loop in Python make issue [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question so earlier I am learning c/c++ and use for loops intensively but now I am learning python and I came

Trying to understand Python loop using underscore and input

One more tip – if anyone is learning Python on HackerRank, knowing this is critical for starting out. I’m trying to understand this code: Output: I put 2 as the first raw input. How does the function know that I’m only looping twice? This is throwing me off because it isn’t the typical…for i in xrange(0,2) structure. At first my

Iterating over two lists one after another

I have two lists list1 and list2 of numbers, and I want to iterate over them with the same instructions. Like this: But that feels redundant. I know I can write for item in list1 + list2:, but it has a price of running-time. Is there a way do that without loose time? Answer This can be done with itertools.chain:

Program to find the nth prime number

I wrote a code in python to find the nth prime number. The code looked fine to me, but it returns an error when I run it: It appears to me as if it is trying to say that I am referring to ptrue in the last line even though I am not. What is the problem here… Can anyone

Advertisement