PYTHON WHILE LOOP HIT OR MISS GAME MULTIPLE USER INPUT | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

PYTHON WHILE LOOP HIT OR MISS GAME MULTIPLE USER INPUT

PROMPT: 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 EXAMPLE INPUT: HIT MISS HIT HIT EXAMPLE OUTPUT: 110 IT FINDS THE FIRST ONE INFINTELY BC I DONT KNOW HOW TO STORE IT AND MOVE ON TO THE NEXT INPUT TO THEN ADD IT ALL TOGETHER.

24th Feb 2021, 7:42 PM
Courtney Ruth
19 Answers
+ 4
For me this worked: score = 100 a = 0 while a <= 3: i = input() if(i == "hit"): score = score + 10 if(i == "miss"): score = score - 20 a = a + 1 print(score)
8th Jun 2021, 10:30 AM
Felix Horn
+ 3
its odd though that i havent gone through learning for loops, the curriculum has only covered while. for loops are next. but the point of this exercise is to use a while loop
24th Feb 2021, 8:00 PM
Courtney Ruth
+ 3
you can then do something like this, score=100 count=4 while count! =0: accuracy=input() if accuracy=="HIT": score+=10 elif accuracy=="MISS": score-=20 count-=1 print(score)
24th Feb 2021, 8:12 PM
Abhay
Abhay - avatar
+ 1
I'm also having issues with this code. Here is what I have so far: #your code goes here x = 0 points = 100 while x < 5: score = input() if score == 'hit': points += 10 if score == 'miss': points -= 20 I'm getting an EOF error, from my research this means the input() is not receiving any data
4th Jun 2021, 1:05 PM
John
+ 1
Its because your „input()“ is not inside the while loop I guess. Because of that, it takes the first input 4 times and doesnt take 4 diffrent inputs
9th Jun 2021, 12:53 PM
Felix Horn
+ 1
Here is the deal: Sololearn does not explain the issue of incorporating the input() function in an appropriate way. I do not know that I must incorporate the input() function INSIDE of the while loop, because I was putting it at the beginning of it, in the first line, like I would do it in Java. I have no idea that I must indicate the function in the block and not out of the block, like a general position. This is something to consider in the future. score = 100 action = 1 while action <= 4: shoot = input() if(shoot == “hit”): score = score + 10 if(shoot == “miss”): score = score – 20 action = action + 1 print(score)
12th Sep 2021, 11:10 PM
Philip Morande
Philip Morande - avatar
+ 1
This will work 100% fine. score = 100 count = 1 while count <= 4: i = input() if(i == "hit"): score = score + 10 if(i == "miss"): score = score - 20 count +=1 print(score)
30th Dec 2021, 8:44 AM
Chinmay Anand
Chinmay Anand - avatar
0
WHAT I HAVE RIGHT NOW ACCURACY = INPUT() SCORE = 100 WHILE ACCURACY: IF ACCURACY == ‘HIT’: PRINT(SCORE + 10) ELIF ACCURACY = ‘MISS’: PRINT(SCORE-20)
24th Feb 2021, 7:45 PM
Courtney Ruth
0
chance = 0 limit = 4 score = 100 while chance < limit: shot = input(f'{chance}. hit or miss: ') if shot == 'hit': score += 10 elif shot == 'miss': score -= 20 chance += 1 print(score)
6th Jul 2021, 9:37 AM
Derrick Gacheru
0
scores = 100 actions = 4 while actions != 0: shoot = input() if shoot == "hit": scores += 10 actions -= 1 elif shoot == "miss": scores -= 20 actions -= 1 print(scores)
11th Sep 2021, 12:06 PM
Andrew Kim
Andrew Kim - avatar
0
score=100 for i in range(4) : accuracy=input() if accuracy=="HIT": score+=10 elif accuracy=="MISS": score-=20 print(score)
18th Nov 2021, 10:12 PM
Neder Said
Neder Said - avatar
0
This seems to work for me score = 100 shot = 3 while shot >= 0: i = input() if i == "hit": score += 10 if i == "miss": score -= 20 shot -= 1 print(score)
31st Dec 2021, 12:20 PM
Eli Hardie Howes
0
score = 100 action = 0 while action <= 3: i = input() if(i == "hit"): score = score + 10 if(i == "miss"): score = score - 20 action +=1 print(score)
27th Jan 2022, 6:49 PM
Alpha Shikaan
Alpha Shikaan - avatar
0
a, running = 100, 0 while running < 4: message = str(input()) if message == 'hit': a = a + 10 running +=1 elif message == 'miss': a = a - 20 running +=1 print(a)
25th May 2022, 6:04 PM
Mazitov Radmir
Mazitov Radmir - avatar
0
score=100 count=4 while count != 0: result = input() if result == "hit": score += 10 elif result == "miss": score -= 20 count -= 1 print(score)
21st Dec 2022, 6:46 AM
Oshan Prabashwara Jayasekara
Oshan Prabashwara Jayasekara - avatar
0
chance=0 limit=4 point=100 while chance<limit: match = input() if match == 'hit': point+=10 elif match == 'miss': point-=20 chance+=1 print(point)
30th Dec 2022, 10:54 AM
Syed Nafis Arefin Ornab
Syed Nafis Arefin Ornab - avatar
0
options = """the options are hit miss stay""" print(options) n = 0 points = 0 while n <= 15: choice = input("what is your choice? ") if choice == "hit": points += 1 print(f"total points:{points} ") elif choice == "miss": points -= 1 print(f"total points:{points} ") elif choice == "stay": points += 0 print(f"total points:{points} ") else: print("type in the right choice") n += 1 print(f"total points:{points} ")
2nd May 2023, 1:42 PM
Roshan Paul
- 1
It should be like, score=100 for i in range(4) : accuracy=input() if accuracy=="HIT": score+=10 elif accuracy=="MISS": score-=20 print(score)
24th Feb 2021, 7:56 PM
Abhay
Abhay - avatar
- 1
I wrote this but it seems to continue with what the first input is, for example, if it starts with ‘hit’ it will repeat that regardless of whether the rest are 'hits' or ‘miss’. if the first input is hit then the answer will be 140, but when the first input is miss, the answer is 20 x = 4 points = 100 accuracy = input() while x > 0: if accuracy == 'hit': points += 10 elif accuracy == 'miss': points -= 20 x -= 1 print(points)
9th Jun 2021, 12:46 PM
Alsadeg Bilal
Alsadeg Bilal - avatar