Hit and miss | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hit and miss

score = 100 count= 0 shoot1= str(input()) shoot2= str(input()) shoot3= str(input()) shoot4= str(input()) while count <4: #First shoot if shoot1 == "hit": score+=10 elif shoot1 == "miss": score-=20 #Second shoot elif shoot2 == "hit": score+=10 elif shoot2 == "miss": score -= 20 #Third shoot elif shoot3 == "hit": score+=10 elif shoot3 == "miss": score -=20 #Forth shoot elif shoot4 == "hit": score +=10 elif shoot4 == "miss": score -=20 else: print("That\'s not a correct input") count +=1 print(score) My question why when I input (hit, miss, hit, miss) say me 140 instead 80

14th Jun 2021, 8:20 AM
Bryan Buenaver
Bryan Buenaver - avatar
7 Answers
+ 2
Thanks Murali but I want to solved by my own code, following the steps from the Application. I didn't touch yet the methods For or List, so it will not help me so much. I just want to know what it's wrong on my code. 😄
14th Jun 2021, 9:24 AM
Bryan Buenaver
Bryan Buenaver - avatar
+ 1
Solved! score =100 x = 0 while x < 4: y=input() if y == "hit": score+=10 if y == "miss": score-=20 x+=1 print(score)
15th Jun 2021, 8:30 AM
Bryan Buenaver
Bryan Buenaver - avatar
0
You only check if 'shoot1' is hit or miss each time. Each shot needs it's own if-else statements to work right the way you coded it. Can't use elif all the way through
14th Jun 2021, 8:44 AM
Slick
Slick - avatar
0
score = 100 count= 0 shoot1= input() shoot2= input() shoot3= input() shoot4= input() #First shoot if shoot1 == "hit": score+=10 elif shoot1 == "miss": score-=20 #Second shoot if shoot2 == "hit": score+=10 elif shoot2 == "miss": score -= 20 #Third shoot if shoot3 == "hit": score+=10 elif shoot3 == "miss": score -=20 #Forth shoot if shoot4 == "hit": score +=10 elif shoot4 == "miss": score -=20 else: print("That\'s not a correct input") count +=1 print(score)
14th Jun 2021, 8:44 AM
SammE
SammE - avatar
0
ch Murali Why assume anything like that? Try not to post codes to answer a coding question. Especially with no explaination. It helps nobody learn
14th Jun 2021, 8:57 AM
Slick
Slick - avatar
- 1
Bryan Buenaver kindly check out the above code to find out the correct answer
14th Jun 2021, 8:50 AM
ch Murali
- 1
Or ch Murali and Rostislav Khalilov you could explain and not just post code.
14th Jun 2021, 8:51 AM
Slick
Slick - avatar