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
7 Respuestas
+ 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. 😄
+ 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)
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
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)
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
- 1
Bryan Buenaver kindly check out the above code to find out the correct answer
- 1
Or ch Murali and Rostislav Khalilov you could explain and not just post code.