+ 1

# Pythons for beginners - Problem 23,3. While loops

Hi everyone. I have a problem with 23,3 problem solving connected with âhit or missâ. My code is here, but the result is wrong. Please help me points = 100 x = 1 while x<=4: if x == 'hit': points += 10 else: x == 'miss' points -= 20 x+=1 print(points)

5th Nov 2021, 11:00 AM
Lilit Harutyunyan
10 Respostas
+ 5
this is according the task description: points = 100 x = 1 # this a counter variable for the number of inputs while x<=4: # there have to be 4 actions to take inp = input() # we need this input for the actions inside the loop if inp == 'hit':# we need to compare 'inp' variable not x variable points += 10 else: #x == 'miss' # this is not valid points -= 20 x+=1# increment the counter print(points)
5th Nov 2021, 11:24 AM
Lothar
+ 5
Lilit s = 100 i = 0 while (i < 4): t = input() if t == "hit": s += 10 else: s -= 20 i+=1 print(s)
5th Nov 2021, 8:34 PM
BroFar
+ 4
Lilit , this code is doing nothing at all in our case, except it overwrites the content of the last input. this does not matter, because it is not affecting the program flow or the result. but you should remove it though. for else clause we can not have a dedicated condion. else covers everything that is not covered by if... or elif... conditions.
5th Nov 2021, 11:46 AM
Lothar
+ 4
Lilit supposedly there is a feature after you miss so many times in code coach solutions that triggers the Solohelper option. Then one of the current solohelper will reach out to you via DM where your code attempt was sent to as well as the link to the code coach solution. I, myself, haven't used it but I am somewhat familiar with the feature.
6th Nov 2021, 8:19 PM
BroFar
+ 4
Lilit Try and try, when say "Get help"(in the answers), touch it and ready
6th Nov 2021, 8:20 PM
CGO!
+ 3
You can send to the SoloHelpers for reciving help
6th Nov 2021, 6:57 PM
CGO!
+ 3
How can I send it? Thanks
6th Nov 2021, 8:01 PM
Lilit Harutyunyan
+ 2
Post the full description pls.. But in your code, there are some mistakes: points = 100 x = 1 #x is an integer now, then while x<=4: if x == 'hit': #(1) this condition is wrong always 1=='hit' , what are you trying here and points += 10 else: x == 'miss' #(2)this is invalid ,and useless instruction .. points -= 20 x+=1 print(points)
5th Nov 2021, 11:16 AM
Jayakrishna đźđł
5th Nov 2021, 11:35 AM
Lilit Harutyunyan
+ 2
Lothar, thank you very much. Anyway I used inp == âmissâ instead of #x == âmissâ Isnât it right too?
5th Nov 2021, 11:38 AM
Lilit Harutyunyan