(Solved)Here is another Code Coach i can't do (Hit or Miss) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

(Solved)Here is another Code Coach i can't do (Hit or Miss)

You are making a game! The player tries to shoot an object and can either 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. Use a while loop to take input during each iteration and calculate the points. Here is my attempt(Copied it from someone): score = 100 shots = 4 while shots>0: result = input() if result == "hit": score+=10 shots-=1 elif result == "miss": score-=20 shots-=1 print(score)

22nd Nov 2021, 9:13 AM
Shah Johan
14 Answers
+ 9
Shah Johan The code you copied is not working for you because of the indentation of the last line of code. But you would be better to make your own code using the principals you have learnt. Have a look at the copied code and see if you can improve it. Review while loops Review variable re-assignment Review operators
22nd Nov 2021, 9:22 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 12
Shah Johan , i have a very boring question: => how can you try to solve a code coach exercice, when you have not started any tutorial? => may be you have an other account? whatever the answer will be, it does not look that your motivation is learning and practicing, as you also mentioned that your code is copied.
22nd Nov 2021, 10:10 AM
Lothar
Lothar - avatar
+ 6
Other users can help you much faster when you 1) tag the relevant programming language 2) put your code into a script, check the indentation and link it here. I have an interesting question: how is it "my attempt" if I "copied it from someone" else?
22nd Nov 2021, 10:18 AM
Lisa
Lisa - avatar
+ 5
Lothar I read recently that the tutorial progress on computers aren't showing on phones. There seems to be some sort of bug where you can't trust the profile progress info.
22nd Nov 2021, 10:17 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 5
Lisa maybe the original code worked and the copying attempt was unsuccessful.
22nd Nov 2021, 5:55 PM
Simon Sauter
Simon Sauter - avatar
+ 4
Shah Johan I will just assume you want to learn. With that in mind, the worst thing you can do is just copy someone else's code. Enlightenment comes, not from just copying code, but from the effort to write your own code. Even if it fails. At least then you learn what does not work. As you work to debug your code you will find those light bulb 💡 moments where you understand. Looking through someone elses code with the goal of understanding why it works is worthwhile too. Don't just copy code, you're short-changing yourself.
22nd Nov 2021, 1:53 PM
Paul K Sadler
Paul K Sadler - avatar
+ 3
Lisa 🤣👍
22nd Nov 2021, 10:20 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
Lothar as Rik pointed out there seems to be a bug with the progress tracking/display. You can see from the badges that they must have started a course. It seems that badges are not affected by the bug.
22nd Nov 2021, 5:29 PM
Simon Sauter
Simon Sauter - avatar
+ 3
That would have been my 2nd question: Why would I copy code from someone else, that obviously doesn't work, Simon Sauter ?
22nd Nov 2021, 5:54 PM
Lisa
Lisa - avatar
+ 2
Lisa it's their attempt to copy someone's code. ;)
22nd Nov 2021, 5:24 PM
Simon Sauter
Simon Sauter - avatar
+ 2
Paul K Sadler Thank you
24th Nov 2021, 8:10 AM
Shah Johan
+ 1
Check indent
24th Nov 2021, 7:47 AM
Laraib Khan
Laraib Khan - avatar
+ 1
Laraib Khan My indent is ok but the problems is the test cases and the expected output my output is different Test cases #1 My output: 110 90 100 80 Expected output: 80 Test cases#2 My output: 80 60 40 50 Expected output: 50
24th Nov 2021, 7:58 AM
Shah Johan
+ 1
Shah Johan your print statement is indented under the while. It should have no spaces or tab before it.
24th Nov 2021, 8:05 AM
Paul K Sadler
Paul K Sadler - avatar