0

Hi, could you help me please, I am with the problem of accumulative points of (Python for Beginners).

You are making a game! The player tries to shoot an object and can hit or miss. The player starts with 100 points, a hit adds 10 points to the player's score, and a miss subtracts 20 points. Your program needs to take 4 action results as input ("hit" or "miss"), calculate and generate the remaining player points. Input example hit hit miss hit Output example 110 ____________________ This is my code: ____________________ y = str(input()) x = 100 i = 1 while i<=4: if y=="hit": x+=10 elif y=="miss": x-=20 print(x) There he asks me for values ​​to infinito lol

29th Apr 2021, 2:49 AM
Kevin Huaripata
Kevin Huaripata - avatar
2 odpowiedzi
+ 2
you are in an infinite loop because y stays the same and does not increase. you have 2 options. remove while i<=4: or add i+=1 after the if statement ends. an example of the code would look something like this. example 1: # this removes the infinite loop by taking out the while loop. y = str(input()) x = 100 i = 1 if y=="hit": x+=10 elif y=="miss": x-=20 print(x) or example 2: # this removes the infinite loop by making i increment up by one at the end of the loop. y = str(input()) x = 100 i = 1 while i<=4: if y=="hit": x+=10 elif y=="miss": x-=20 i+=1 print(x)
29th Apr 2021, 3:14 AM
you are smart. you are brave.
you are smart. you are brave. - avatar
0
Also try to put the i + = 1 but now it only asks for a value and the final result is applied only for that value, but they have to be four different values, this is the problem: You are making a game! The player tries to shoot an object and can hit or miss. The player starts with 100 points, a hit adds 10 points to the player's score, and a miss subtracts 20 points. Your program needs to take 4 action results as input ("hit" or "miss"), calculate and generate the remaining player points. Input example hit hit miss hit Output example 110
29th Apr 2021, 4:04 AM
Kevin Huaripata
Kevin Huaripata - avatar