+ 2
I can't understand while loop in python
It's a bit confusing
8 Respostas
+ 1
Roselyne Anjie I also encountered that yesterday and I posted it on my feed for help on how to solve it and nobody answered so I just skipped it. When I get better I will go back to it, I think you should do the same
+ 4
Think about it as a sentence. Say i wanted to pick up cans all day, unless there was a lightning storm.
while(there's no storm)
pick up cans
Its just a way to do something over and over until a specific condition is met to stop it
+ 3
You said while loop. While loop is for an undetermined amount of cycles.
Use a for loop, because it gives you the number of inputs
0
what exactly you didn't understand?
0
Give an example than its better to explane that
0
Here is it , it's a problem
0
You are making a game! The player tries to shoot an object and can hit or miss it.
The player starts with 100 points, with a hit adding 10 points to the player’s score, and a miss deducting 20 points.
Your program needs to take 4 action results as input ("hit" or "miss"), calculate and output the player’s remaining points.
Sample Input
hit
hit
miss
hit
Sample Output
110
Explanation: 3 hits add 30 points, one miss deducts 20, making the total points equal to 110.
0
An example is
a = 0
while a < 3:
print(a)
a = a + 1
This prints incremented value of a by 1, 3 times